我一直在为基于文本的游戏开店。我已经得到了一切工作......除了结束。最后,程序会问玩家“就这样吗?” 无论您输入什么,都会被放入一个名为 answer 的变量中。然后根据您输入的内容,应该将您返回到调用 shop() 或再次调用 shop() 的行。这是代码。
print('Would that be all?')
answer =input()
if answer ='yes'.startswith('y'):
return
我一直在为基于文本的游戏开店。我已经得到了一切工作......除了结束。最后,程序会问玩家“就这样吗?” 无论您输入什么,都会被放入一个名为 answer 的变量中。然后根据您输入的内容,应该将您返回到调用 shop() 或再次调用 shop() 的行。这是代码。
print('Would that be all?')
answer =input()
if answer ='yes'.startswith('y'):
return
你不符合你的条件(我添加了一个lower()
不区分大小写的;)):
print('Would that be all?')
answer = input()
if answer.lower().startswith('y'):
return
首先,要测试两个事物是否相等,您需要使用“==”(相等比较符号),而不是“=”(赋值符号)。
其次,您似乎无法决定是否要测试答案是否等于“是”或答案是否以“y”开头。我认为你需要选择一个:
print('Would that be all?')
answer = input()
if answer == 'yes':
return
或者
print('Would that be all?')
answer = input()
if answer.startswith('y'):
return
你应该使用:
if answer.startwith('y'):
或者
if answer == 'yes':
或类似的。