Python 如何计算某个数字而不是实际数字的长度?
我想发生的是,如果控制台打印的数字超过500,但现在它计算的是数字的长度,而不是数字的数值有多高Python 如何计算某个数字而不是实际数字的长度?,python,Python,我想发生的是,如果控制台打印的数字超过500,但现在它计算的是数字的长度,而不是数字的数值有多高 print ("What Is The Current Distance In Meters?") distance = input () if len (distance) >= 500: (print) ("Thanks") 您需要首先将距离转换为一个数字,然后使用大于运算符,这样您的代码就变成: print ("What Is The Current Distance I
print ("What Is The Current Distance In Meters?")
distance = input ()
if len (distance) >= 500:
(print) ("Thanks")
您需要首先将距离转换为一个数字,然后使用大于运算符
,这样您的代码就变成:
print ("What Is The Current Distance In Meters?")
distance = input ()
if int(distance) > 500 :
print ("Thanks")
希望我能帮忙
input()
始终是一个字符串-您可能需要distance=int(input())
int(distance)
?为什么要在print
中插入括号?