Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何计算某个数字而不是实际数字的长度?_Python - Fatal编程技术网

Python 如何计算某个数字而不是实际数字的长度?

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

我想发生的是,如果控制台打印的数字超过500,但现在它计算的是数字的长度,而不是数字的数值有多高

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
中插入括号?