[英]Need Some Help on Python Code
這是我的Python代碼,用於計算電費
cust=input("Enter Customer Number\n");
units=input("Enter No of Units\n");
if(units<200&units>0):
bill=0.50*units;
elif(units>200&units<400):
bill=100+(0.65*(units-200))
print"\n in Loop2\n"
elif(units>400&units<600):
bill=230+(0.80*(units-400))
print"\n in Loop3\n"
print"Bill For Customer Number ",cust," is ",bill
如果我將單位設置為200+,則在Loop 2中但是如果我將單位設置為430,它仍在Loop2中運行
我是python新手,所以需要一些幫助
cust=input("Enter Customer Number\n");
units=input("Enter No of Units\n");
if(units<200 and units>0):
bill=0.50*units
elif(units>200 and units<400):
bill=100+(0.65*(units-200))
print"\n in Loop2\n"
elif(units>400 and units<600):
bill=230+(0.80*(units-400))
print"\n in Loop3\n"
print"Bill For Customer Number ",cust," is ",bill
使用“和”代替“&”。 布爾運算符通常用於布爾值,而按位運算符通常用於整數值。 “和”測試兩個表達式在邏輯上是否為True,而“&”(與True / False值一起使用)測試兩個表達式是否均為True。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.