2017-09-23 77 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