为了账号安全,请及时绑定邮箱和手机立即绑定

请问“无法排序的类型:int()<str()”怎么办

请问“无法排序的类型:int()<str()”怎么办

噜噜哒 2019-12-19 18:13:10
我正在尝试在Python上制作退休计算器。语法没有错,但是当我运行以下程序时:def main():    print("Let me Retire Financial Calculator")    deposit = input("Please input annual deposit in dollars: $")    rate = input ("Please input annual rate in percentage: %")    time = input("How many years until retirement?")    x = 0    value = 0    while (x < time):        x = x + 1        value = (value * rate) + deposit        print("The value of your account after" +str(time) + "years will be $" + str(value))它告诉我:Traceback (most recent call last):  File "/Users/myname/Documents/Let Me Retire.py", line 8, in <module>    while (x < time):TypeError: unorderable types: int() < str()有什么想法可以解决这个问题吗?
查看完整描述

2 回答

?
海绵宝宝撒

TA贡献1809条经验 获得超8个赞

附带说明一下,在Python 2.0中,您可以将任何事物与任何事物进行比较(从int到string)。由于这不是很明显,因此在3.0中进行了更改,这是一件好事,因为您不会遇到将无意义的值相互比较的麻烦,或者当您忘记转换类型时。


查看完整回答
反对 回复 2019-12-28
  • 2 回答
  • 0 关注
  • 391 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信