python not support int and str_类型错误:“int”和“str”的实例之间不支持“<”

我猜了一下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: '

为什么它支持但不支持?

感谢大家的帮助。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值