我正在嘗試編寫一個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
您需要縮進'if'語句的正文。 – Barmar
有一個編輯掛起正確縮進'if'語句的正文。請注意待處理的編輯。 – ndim