这是我的代码:
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()
我试图让程序执行此操作:
以下是输出结果的示例:
python3 commline.py True "Peter Pan" 3.14159 7
True
Peter Pan
3.14159
7
Result:
10.14159
答案 0 :(得分:2)
使用len()
:
if a == True and len(b) > d: