2017-09-23 85 views
0

我正在尝试编写一个Python程序,收取停放多少小时的停车费。直到分钟超过300计算停车费。 '&'versus'and'

我已经打了回报,每次我这样做,输入后,我会得到圆满完成无输出时间

,一切工作正常。

当我投入600分钟(10小时)的时候,应该是30美元,我得到40美元的费用。

这里是我的代码:

import math 
rate1 = 5 
rate2 = 4 
rate3 = 3 


m = int(input('Please enter the number of minutes parked: ')) 

if m <= 60: 
    x = m/60 
    fee = math.ceil(x) * 5 
    print('Parking fee for',m,'minutes is $',fee) 

elif m>60 & m<=300: 
    x = m/60 
    fee = math.ceil(x) * rate2 
    print('Parking fee for',m,'minutes is $',fee) 

elif m>300: 
    x = m/60 
    fee = math.ceil(x) * rate3 
    print('Parking fee for',m,'minutes is $',fee) 

else: 
    print('Invalid input') 

输出:

Please enter the number of minutes parked: 600 
Parking fee for 600 minutes is $ 40 

Process finished with exit code 0 
+3

您需要缩进'if'语句的正文。 – Barmar

+0

有一个编辑挂起正确缩进'if'语句的正文。请注意待处理的编辑。 – ndim

回答

4
if m > 60 & m <= 300: 

应该是:

if m > 60 and m <= 300: 

if 60 < m <= 300: 

&是逐位AND操作者,and是逻辑AND操作者(这类似于在C,PHP &&&之间的差,和Javascript)。

+0

你的意思是'60 Elmex80s

+0

我会尝试一下,我希望它可以工作,最简单的事情可以是最难的哈哈,我会在30分钟内更新当我回到电脑! – sully

+0

它的工作!哇...我不能相信如此简单的事情让我今天3个小时难倒...非常感谢Barmar! – sully