简体   繁体   English

是我的程序无法执行它的原因是收到正确输入后的ifif else语句

[英]?Is there a reason why my program won't perform it's if elif else statement after receiving proper input

Basically, the goal of this program is to take input from the user on what they want to order, process the cost of the item and tack on sales tax and a tip and return that. 基本上,该程序的目标是从用户那里获得他们想要订购的内容的输入,处理商品的成本以及附加营业税和小费并退还小费。 I'm struggling with how to go about getting my program to take input and run an if elif else statement based on what the input is. 我正在努力使程序接受输入并根据输入内容运行if if else语句。 I'm fairly new and I'm still figuring out how to ask a constructive question, so bear with me here. 我还很新,我还在想办法问一个建设性的问题,所以请在这里忍受。 Also, I know there a bits of it that are unfinished, which may factor into it, but I'm not really concerned with the incomplete bits 另外,我知道其中有一些未完成的部分,可能会纳入其中,但我并不真正担心未完成的部分

I've tried making the if statement conditions dependent on the input given using the == operator as well as changing that to an "if answer is __: print a response. I'm fairly confident that I can get the program to print out a tip and tax tacked onto a price, but everything I've tried so far keeps exiting my program after receiving any form of input. 我尝试使if语句条件取决于使用==运算符给出的输入,并将其更改为“ 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")

I expect it to take 'goose' as an answer and print a response (eventually i'd make this take the number assigned to goose and calculate tax), but it simply ignores any input every single time. 我希望它以“鹅”作为答案并打印响应(最终,我将使用分配给鹅的数字来计算税款),但它每次都忽略任何输入。

输入是一个内置函数,您应该分配从输入获取的值,但是您的代码会将函数本身分配给变量答案

answer = input('Hon hon, what\'ll it be, monsieur? the goose, stake or narwhal?')

You need to assign your input to a variable. 您需要将输入分配给变量。 Your input is just reading from the keyboard and you don't save that value. 您的输入只是从键盘上读取的,您没有保存该值。 Fix this with: 使用以下方法解决此问题:

answer = input('Hon hon, what\'ll it be, monsieur? the goose, stake or narwhal?')

if answer == 'goose':

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM