中断功能在 Python 3.5 中不起作用!我不知道为什么。我需要建议

Break function not working in Python 3.5! i dont know why. i need advise

好的,所以我尝试制作一个数字猜谜游戏...没有用,所以我转向了 youtube。 我什至尝试复制别人的代码!仍然没有为我工作。这是我的代码。

import random
import time

print('This is a guessing gamefrom 1-1000.')

num = random.randint(1, 1000)

time = time.time()

guess = int(input('what number do you guess? '))

playing = True

while(playing):
    if guess < num:
        print('Guess is too low!')
    elif guess > num:
        print('Guess is too High!')
    elif guess == num:
        break

print('Nice job!')

time2 = time.time()

totalTime = str(int(time2-time1))

print('you took ' + totalTime + 'seconds to guess the number')

如果我 运行 它并输入一个数字,它会重复 "answer is too high" 或 "answer is too low" 我不知道该怎么做。

如果你不要求重新猜测,你要么在第一次尝试就猜对并跳出循环,要么你将永远循环,因为错误的 guess 将是相同的在每次迭代中。要解决此问题,请在 while 循环中每次重新分配 guess

time = time.time()

playing = True

while(playing):
    guess = int(input('what number do you guess? '))
    if guess < num:
        # etc.