Ваша структура кода неверна.
-
if-elif-else
должно быть внутри while
l oop. - * * * * * * * * * * * * * * * * должно быть определено за пределами
while
l oop, потому что они были установлены в 0 в каждом l oop (из-за этого ваш "4 option" ничего не показал). - Я рекомендую печатать только один раз использование (вне
while
l oop.)
Рабочий код:
# The following variables should be outside of while loop because these are erased in every loop.
amount = 0
count = 0
# Suggested to print the usage only once. Not in every loop.
print("Press 1 For Rickshaw")
print("Press 2 For Car")
print("Press 3 For Bus")
print("Press 4 To Show The Record")
print("Press 5 To Delete The Record")
print("press 6 to exit\n")
while True:
u_ip = int(input("Please write your option: "))
# is-elif-else should be inside the while loop!
if u_ip == 1:
amount = amount + 100
count = count + 1
elif u_ip == 2:
amount = amount + 200
count = count + 2
elif u_ip == 3:
amount = amount + 300 # Typo issue. It should be "amount"
count = count + 3
elif u_ip == 4:
print("\nThe Total amount: {}".format(int(amount)))
print("The Total Number of vehicle parked = {}\n".format(int(count)))
elif u_ip == 5:
amount = 0
count = 0
elif u_ip == 6:
break
else:
print("Invalid Number\n")
Тест:
>>> python3 test.py
Press 1 For Rickshaw
Press 2 For Car
Press 3 For Bus
Press 4 To Show The Record
Press 5 To Delete The Record
press 6 to exit
Please write your option: 1
Please write your option: 2
Please write your option: 4
The Total amount: 300
The Total Number of vehicle parked = 3
Please write your option: 5
Please write your option: 4
The Total amount: 0
The Total Number of vehicle parked = 0
Please write your option: 3
Please write your option: 4
The Total amount: 300
The Total Number of vehicle parked = 3
Please write your option: 6