【发布时间】:2016-07-06 06:57:04
【问题描述】:
Distance = input("How far are you from the spacecraft in meters? (full positive numbers) \n")
number = Distance.isdigit()
while number == False:
print ("Please enter a number or full number")
Distance = input("How far are you from the spacecraft in meters? (full positive numbers) \n")
number = Distance.isdigit()
while Distance < 600:
print ("Please move back further from the space craft! \n")
Distance = input("How far are you from the spacecraft in meters? (full positive numbers) \n")
所以我试图将一个字符串与一个整数进行比较,但我不确定如何在不破坏这部分的情况下解决这个问题
数字 = 距离.isdigit() 而数字 == 错误:
【问题讨论】:
-
你可以投:
Distance = int(input("blabla")) -
尝试使用 int(input("somestringinput")) 进行强制转换,并在输入字符串为 NAN 时将其放入 try-except 块中以正确处理。
标签: string python-3.x int helper