unorderable类型:str()> int()python

时间:2014-05-01 10:50:39

标签: python

这是我的代码:

import sys

def main():
   a = bool(sys.argv[1])
   b = str(sys.argv[2])
   c = float(sys.argv[3])
   d = int(sys.argv[4])
   for x in sys.argv:
      print(x)
   if a == True and b > d:
      print(c+d)
   else:
      b_upper = b.upper()
      print(b_upper)




main()

我收到此错误:

File "commline.py", line 19, in <module>
   main()
File "commline.py", line 10, in main
   if a == True and b > d:
TypeError: unorderable types: str() > int()

我试图让程序执行此操作:

  • 如果布尔值为True并且字符串的长度大于整数值,则打印float和整数的总和
  • 否则,打印转换为大写的字符串

以下是输出结果的示例:

python3 commline.py True "Peter Pan" 3.14159 7
True
Peter Pan
3.14159
7
Result:
10.14159

1 个答案:

答案 0 :(得分:2)

使用len()

if a == True and len(b) > d: