def main():
total = 0
print('Welcome to the Dew Drop Inn!')
print('Please enter your choices as y or n.')
print(' ')
cheese = (input('Do you want a grilled cheese? '))
dog = (input('Do you want a hot dog? '))
nacho = (input('Do you want nachos? '))
burger = (input('Do you want a hamburger? '))
grilled_cheese = 5
hot_dog = 5
nachos = 4
hamburger = 6
cheese_burger = 1
if cheese == 'y':
total + grilled_cheese
if dog == 'y':
total + hot_dog
if nacho == 'y':
total + nachos
if burger == 'y':
total + hamburger
the_cheese_please = input('Do you want cheese on that? ')
if the_cheese_please == 'y':
total + cheese_burger
else:
total + 0
print(' ')
print('The total for your food is $',(total),'.')
tip = total * 1.15
main()
我需要能夠從用戶告訴我加起來的數字。根據他們想要什麼食物,我該如何使用if/else語句來添加數字? if的最大數量是5,else的最大數量是1.我很新,所以我很抱歉如果這看起來很天真,但如果有人給我一個小費,這真的會幫助我。謝謝!使用if/else語句添加數字?
到底是什麼錯,你發佈的代碼? – csmckelvey
你是一個不錯的翻車手,確定它不應該是'tip = total * 0.15'? – Mitchel0022
通過諸如pylint之類的工具或使用適當的python ide來運行此代碼可以很快地突出顯示此問題。 – Shadow