2017-10-14 74 views
1

一些帮助,这是我的Python代码来计算电费需要对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多家是在环2 但是,如果我给单位430它是在仍然运行环2

我新的Python所以需要一些帮助

+1

你可以使用这个语法:'如果0 <单位<200:'... – PRMoureu

+1

考虑强制单位'int':'单位= INT(单位)' – snakecharmerb

+0

谢谢snakecharmerb – user3123757

回答

2
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。