简体   繁体   中英

?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. 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.

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':

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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