【发布时间】:2019-08-14 16:19:30
【问题描述】:
我是代码的初学者。我已经为我的家庭作业编写了这段代码(这是一个精简版),但是每当我按下播放并开始这个过程时,无论我输入多少边,它总是要求一些平行边,然后猜测和等腰三角形.为什么会这样?
print("Shape Guesser Game \n-----------------")
print("Welcome to the Shape Guesser Game! \nI believe that I can guess the shape you think of.")
print("There is only 1 rule: \nYou can only think of a polygon with a maximum of 6 sides.")
response_1 = input("\nDo you want to play? \nPick Yes or No")
if response_1 == "Yes" or "yes":
print("Great! Let's get started! \n------------------")
response_2 = input("Have you thought of your shape? Yes/No")
if response_2 == "Yes" or "yes":
response_3 = input("How many sides does it have?")
if response_3 == "3" or "three":
response_4 = input("How many equal sides does it have?")
if response_4 == "2" or "two":
response_5 = input("Aha! It is an isosceles triangle! Am I right? Yes or No?")
if response_5 == "yes" or "Yes":
print("Yay I have succeeded! Thank you for playing this game. \nGo back to Home.")
elif response_4 == "3" or "three":
response_6 = input("Aha! It is an equilateral triangle! Am I right? Yes or No?")
print("Yay I have succeeded! Thank you for playing this game. \nGo back to Home.")
else:
print("Not valid:Error \n-------------")
elif response_3 == "4" or "four":
response_7 = input("How many parallel sides does it have?")
if response_7 == "two" or "2":
response_8 = input("Aha! It is a trapezium! Am I right? Yes or No?")
if response_8 == "yes" or "Yes":
print("Yay I have succeeded! Thank you for playing this game. \nGo back to Home.")
if response_7 == "four" or "4":
response_9 = input("Aha! It is a parallelogram! Am I right? Yes or No?")
if response_9 == "yes" or "Yes":
print("Yay I have succeeded! Thank you for playing this game. \nGo back to Home.")
elif response_2 == "No" or "no":
print("Okay no worries, I will give you more time!")
elif response_1 == "No" or "no":
print("Sad to see you go! Back to Home.")
【问题讨论】:
-
除了通过将
if response_1 == "Yes" or "yes"更改为if response_1 == "Yes" or response_1 == "yes"来修复之外,您还可以将if作为if response_1 in ("Yes", "yes")进行检查。当您需要与多个值进行比较时,这可能会很好。
标签: python