此代码根本不起作用。它甚至不执行。有人可以帮我修复它吗?
我是使用 Python 的新手,我正在尝试创建一个程序,该程序会根据您给出的答案告诉您您可能喜欢哪种葡萄酒。
我需要帮助。
wine1 = input("Do you like citrus flavours like lemon and lime? Type 1 if true:\n")
wine2 = input("Type 2 to move on to question 2:\n")
wine3 = input("Do you like red berry flavours like raspberry and cranberry? Type 3 if true:\n")
wine4 = input("Type 4 to move on to question 3:\n")
wine5 = input("Do you like stone fruit flavours like peach and plum? Type 5 if true:\n")
wine6 = input("Type 6 to move on to question 4:\n")
wine7 = input("Do you like oak? Type 7 if true:\n")
wine8 = input("Type 8 to move on to question 5:\n")
wine9 = input("Do you like bold, full bodied wines? Type 9 if true:\n")
wine10 = input("Type 10 to move on to question 6:\n")
wine11 = input("Do you like floral flavours? Type 11 if true:\n")
wine12 = input("Type 12 to move on to question 7:\n")
wine13 = input("Do you like red or white wine? Type 13 if true:\n")
wine14 = input("Type 14 to end the quiz:\n")
v1 = int(wine1)
v2 = int(wine2)
v3 = int(wine3)
v4 = int(wine4)
v5 = int(wine5)
v6 = int(wine6)
v7 = int(wine7)
v8 = int(wine8)
v9 = int(wine9)
v10 = int(wine10)
v11 = int(wine11)
v12 = int(wine12)
v13 = int(wine13)
v14 = int(wine14)
choice = input("1.\n2.\n3.\n4.\n5.\n6.\n7.\n8.\n9.\n10.\n11.\n12.\n13.\n14.:\n")choice = int(choice)
if choice == 1:
print(f'You chose {v1} You will enjoy a Pinot Grigio')
if choice == 2:
print(f'You chose {v2} Move on to question 2')
if choice == 3:
print(f'Your chose {v3} You will enjoy a Pinot Noir')
if choice == 4:
print(f'Your chose {v4} Move on to question 3')
if choice == 5:
print(f'You chose {v5} You will enjoy a Shiraz or a Riesling')
if choice == 6:
print(f'You chose {v6} Move on to question 4')
if choice == 7:
print(f'You chose {v7} You will enjoy an Oaked Chardonnay or a Bordeaux Blend')
if choice == 8:
print(f'You chose {v8} Move on to question 5')
if choice == 9:
print(f'You chose {v9} You will enjoy a Malbec or a Shiraz')
if choice == 10:
print(f'You chose {v10} Move on to question 6')
if choice == 11:
print(f'You chose {v11} You will enjoy a Riesling or a Shiraz')
if choice == 12:
print(f'You chose {v12} Move on to question 7')
if choice == 13:
print(f'You chose {v13} Why not try a new red wine today. Check out')
if choice == 14:
print(f'You chose {v14} Why not try a new white wine today. Check out')
else:
print("Oops, you didn't follow the rules. Try again.")
答案 0 :(得分:0)
File "stack.py", line 31
choice = input("1.\n2.\n3.\n4.\n5.\n6.\n7.\n8.\n9.\n10.\n11.\n12.\n13.\n14.:\n")choice = int(choice)
^
SyntaxError: invalid syntax
错误消息显示您的语法无效。将 choice = int(choice)
移到新行。
答案 1 :(得分:0)
为了使此代码工作,您需要将 choice = int(choice) 放在新行中。我认为这可能是一个错误,所以只需修复它:)