【发布时间】:2019-01-30 02:53:15
【问题描述】:
基本上,该计划的目标是听取用户对他们想要订购的商品的意见,处理商品的成本,加上销售税和小费,然后将其退回。我正在努力让我的程序接受输入并根据输入的内容运行 if elif else 语句。 我还很新,我还在想办法提出建设性的问题,所以请耐心等待。另外,我知道其中有一些未完成的部分,这可能是其中的一个因素,但我并不真正关心不完整的部分
我尝试使 if 语句条件依赖于使用 == 运算符给出的输入,并将其更改为“如果答案是 __:打印响应。我相当有信心我可以得到程序打印出贴在价格上的小费和税款,但到目前为止我尝试过的所有内容在收到任何形式的输入后都会退出我的程序。
salesTax = 0.07 #the tax added onto the total
tip= 0.18 #the percentage for a tip
steak= 96 # a var for a steak priced so deliciously, that it *must* be good.
goose= 42 #var for the oddly familiar, yet disturbingly alien meal that is goose.
narwhal= 109 #var for a meal that questions its own existence, then laughs in the face of that question
menu = ['high-stakes steak', 'uncanny boiled goose', 'endangered carribrean narwhal caccitore']
print("Tonight's menu at Joe's ethically questionable eatery includes")
print(menu)
input('Hon hon, what\'ll it be, monsieur? the goose, stake or narwhal?')
answer = input
if answer == 'goose':
print("Ah, very good monsieur the cost will be 42. We will beegen ze cooking of ze goose")
elif answer is 'steak':
print("Ah, a high roller, we will begin")
我希望它将“goose”作为答案并打印一个响应(最终我会让它采用分配给 goose 的数字并计算税款),但它每次都会忽略任何输入。
【问题讨论】:
-
你的缩进被破坏了......
-
answer = input是干什么用的?把它去掉,把上一行改成answer = input('Hon hon...) 还有answer is 'steak'不是你想的那样;将其更改为answer == 'steak',就像你对鹅所做的那样。
标签: python if-statement conditional