擅长:python、mysql、java
<p>您需要在while循环中获取用户的输入,以便用户的输入在每次迭代中都得到更新。在</p>
<pre><code>import random
num = (random.randint(1,10))
while True:
try:
guess = int(input("Guess a number 1 through 10: "))
if guess == num:
print("you guessed the right number!")
break
else:
print("try again")
except:
print('Invalid Input')
</code></pre>