String 如何在python中将字符串设置为整数 Distance=input(“您离航天器有多远,以米为单位?(完整正数)\n”) 数字=距离。isdigit() 当number==False时: 打印(“请输入数字或完整数字”) 距离=输入(“您离航天器有多远,以米为单位?(完整正数)\n”) 数字=距离。isdigit() 距离

String 如何在python中将字符串设置为整数 Distance=input(“您离航天器有多远,以米为单位?(完整正数)\n”) 数字=距离。isdigit() 当number==False时: 打印(“请输入数字或完整数字”) 距离=输入(“您离航天器有多远,以米为单位?(完整正数)\n”) 数字=距离。isdigit() 距离,string,python-3.x,int,helper,String,Python 3.x,Int,Helper,所以我试图将一个字符串与一个整数进行比较,但我不确定如何在不破坏这一部分的情况下解决这个问题 数字=距离。isdigit() 而number==False:我想你可以用这个 Distance = input("How far are you from the spacecraft in meters? (full positive numbers) \n") number = Distance.isdigit() while number == False:

所以我试图将一个字符串与一个整数进行比较,但我不确定如何在不破坏这一部分的情况下解决这个问题

数字=距离。isdigit()
而number==False:

我想你可以用这个

    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")

我想你可以用这个

    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")

您可以强制转换:
Distance=int(输入(“blablabla”)
尝试使用int(输入(“somestringinput”))强制转换,并将其放入Try-except块,以便在输入字符串为NAN时正确处理。您可以强制转换:
Distance=int(输入(“blablabla”)
尝试使用int(输入(“somestringinput”))强制转换并将其放入try-except块中,以便在输入字符串为NAN时正确处理它。