当我们编程时,有时会出现如下错误:TypeError: '>' not supported between instances of 'str' and 'int'

如下图:

报错:TypeError: '>' not supported between instances of 'str' and 'int'

这是因为input()返回的数据类型是str类型,不能直接和整数进行比较,必须先把str转换成整型,使用int()方法:age = int(input ("请输入你的年龄:"))

改正之后为:

报错:TypeError: '>' not supported between instances of 'str' and 'int'

这样程序就达到了预期的效果了

相关文章:

  • 2021-04-20
  • 2022-12-23
  • 2021-06-25
  • 2022-12-23
  • 2022-12-23
  • 2021-07-20
  • 2021-06-18
猜你喜欢
  • 2022-12-23
  • 2021-05-14
  • 2022-12-23
  • 2021-07-08
  • 2022-12-23
  • 2021-10-07
  • 2022-12-23
相关资源
相似解决方案