Python 如果;这";答案是,返回上一行
我目前正在学习Python,并想知道一些事情。我正在编写一个小文本冒险游戏,需要以下方面的帮助: 例如,如果我写作Python 如果;这";答案是,返回上一行,python,loops,input,Python,Loops,Input,我目前正在学习Python,并想知道一些事情。我正在编写一个小文本冒险游戏,需要以下方面的帮助: 例如,如果我写作 example = input("Blah blah blah: ") if example <= 20 and > 10: decision = raw_input("Are you sure this is your answer?: ") example=input(“废话废话:”) 如果示例10: 决策=原始输入(“您确定这是您的答案吗?”) 我可以
example = input("Blah blah blah: ")
if example <= 20 and > 10:
decision = raw_input("Are you sure this is your answer?: ")
example=input(“废话废话:”)
如果示例10:
决策=原始输入(“您确定这是您的答案吗?”)
我可以编写哪些函数使“example=input”(“诸如此类”)再次运行?如果用户对“decision=raw_input”(“您确定这是您的答案吗?”)说不
对不起,我把你们都弄糊涂了。我对Python和编程有点生疏。您正在寻找
while
循环:
decision = "no"
while decision.lower() == "no":
example = input("Blah blah blah: ")
if 10 < example <= 20:
decision = raw_input("Are you sure this is your answer?: ")
decision=“否”
while decision.lower()=“否”:
示例=输入(“诸如此类:”)
如果10
def test():
example = input("Blah blah blah: ")
if example in range(10, 21): # if it is between 10 and 20; second argument is exclusive
decision = raw_input("Are you sure this is your answer?: ")
if decision == 'yes' or desicion == 'Yes':
# code on what to do
else: test()
else: # it will keep calling this until the input becomes valid
print "Invalid input. Try again."
test()
该条件的正确语法是10<示例谢谢,这非常有帮助!这仍然是一种实现他想要的方法:)可能,但过度复杂是一种不好的做法,会导致不必要的限制(例如最大递归深度)。