擅长:python、mysql、java
<h2>Python不支持<code>goto</code>或任何等价的东西</h2>
<p>您应该考虑如何使用python提供的工具构造程序。似乎需要使用循环来完成所需的逻辑。您应该查看<a href="https://docs.python.org/3/tutorial/controlflow.html" rel="nofollow">control flow page</a>了解更多信息。</p>
<pre><code>x = random.randint(0,100)
correct = False
prompt = "Guess the number between 1 and 100: "
while not correct:
y = int(raw_input(prompt))
if isinstance(y, int):
if y == x:
correct = True
elif y > x:
prompt = "Wrong! Try a LOWER number: "
elif y < x:
prompt = "Wrong! Try a HIGHER number "
else:
print "Try using a integer number"
</code></pre>
<p>在许多其他情况下,您将希望使用<a href="https://docs.python.org/3/tutorial/controlflow.html#defining-functions" rel="nofollow">function</a>来处理要使用goto语句的逻辑。</p>