我猜了一下Python3.6中的数字程序,这是我的代码。import random
guesses = 0
print('Hello! What is your name?')
name = input()
num = random.randint(1,10)
print('well',name,'I am thinking of a number between 1 and 20.')
while guesses < 4:
print('Take a guess.')
guess = input()
guess = int(guess)
guesses = guesses + 1
if guess < num:
print('Your guess is too low.')
if guess > num:
print('Your guess is too high.')
if guess == num:
guesses = str(guessesTaken)
print('Good job, ',name,'! You guessed my number in ',guesses,' guesses!')
if guess != num:
num = str(num)
print('Nope. The number I was thinking of was ',num)
当我运行代码时,它会显示以下错误消息Hello! What is your name?
h
well h I am thinking of a number between 1 and 20.
Take a guess.
7
Your guess is too low.
Nope. The number I was thinking of was 10
Take a guess.
5
Traceback (most recent call last):
File "C:\Users\user\Desktop\Number game.py", line 13, in
if guess < num:
TypeError: '
为什么它支持但不支持?
感谢大家的帮助。