python学习遇到的问题

python学习-TypeError: ‘<=’ not supported between instances of ‘str’ and 'int’问题

今天学习python遇到TypeError: ‘<=’ not supported between instances of ‘str’ and 'int问题
在这里插入图片描述
在这里插入图片描述
报错原因是:input()输入的内容是一个字符串,字符串跟整型数值进行比较,类型不匹配

修改方法:

i = int(input())

把其转化为整形就?辽

print("-----猜数字游戏-----")
print("请输入1-10之间的任意一个数")
i=int(input())
print(i)
if i<=9:
    print("太小,请重新输入")
else :print("恭喜你,你赢了,猜中的数字是:"+str(i))

原创文章 20 获赞 14 访问量 2172

猜你喜欢

转载自blog.csdn.net/qq_42166929/article/details/97623336