gpt4 book ai didi

python - 相当于python中的GOTO

转载 作者:IT老高 更新时间:2023-10-28 21:35:53 26 4
gpt4 key购买 nike

我正在自学 python 2.7。我有一些使用 BATCH 的经验,它有一个 GOTO 语句。我如何在 python 中做到这一点?例如,假设我想从第 5 行跳到第 18 行。

我意识到以前有关于这个主题的问题,但我没有发现它们提供足够的信息,或者对于我目前的理解来说,它们在 python 中的水平太高了。

最佳答案

原谅我 - 我无法抗拒 ;-)

def goto(linenum):
global line
line = linenum

line = 1
while True:
if line == 1:
response = raw_input("yes or no? ")
if response == "yes":
goto(2)
elif response == "no":
goto(3)
else:
goto(100)
elif line == 2:
print "Thank you for the yes!"
goto(20)
elif line == 3:
print "Thank you for the no!"
goto(20)
elif line == 20:
break
elif line == 100:
print "You're annoying me - answer the question!"
goto(1)

关于python - 相当于python中的GOTO,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18863309/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com