【发布时间】:2022-01-24 18:10:16
【问题描述】:
我目前正在为这项工作编写一个 Tipper 程序,但我遇到了很多问题。结果一直说语法无效,我已经切换了很多东西,但似乎我永远无法让它恰到好处。举个例子,这是我当前的代码:
print("Now that your belly is full, how much is the fee?")
fee = input("Enter your fee: ")
print("Would you like to give us a tip?")
answer = input("Yes or no?")
if answer == no:
why = input("Why do you not want to tip us? Also, you don't have to answer. When done, just press enter.")
print("We understand. Here is your fee:", fee)
elif answer == yes:
tip = input("Would you like to tip 15 percent or 20 percent? ")
if tip == 15 :
cost1 = fee/15 + fee
elif tip == 20 :
cost2 = fee/20 + fee
else:
print("I do not understand.")
else:
print("I do not understand.")
print:("Have a wonderful day!")
所以,是的,老实说,我不确定为什么它不起作用,但有人可以回答吗?我真的被这件事难住了。
【问题讨论】:
-
if answer == no:...你提到if answer == "no":? -
tip = input("Would you like to tip 15 percent or 20 percent? ") if tip == 15 :- tip 是一个字符串,绝不是 15。 -
为什么我需要 tilp 15 或 20 - 也许我只想给 8% ... 或固定金额 ....
-
其中可能还有很多其他错误......也许你应该在生产生产代码之前学习how to debug small programs
-
好的,那么我应该在 15 和小费之间放什么?
标签: python python-3.x