Liam Gibson
Liam Gibson

Reputation: 1

how to make a string an integer in python

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

So I am trying to compare a string to a integer but I'm not sure how to fix that with out breaking this part

number = Distance.isdigit() while number == False:

Upvotes: 0

Views: 114

Answers (1)

badiya
badiya

Reputation: 2257

I think you can use this.

def is_digit(Distance):
    try:
        if int(Distance) & int(Distance) >0:
            return True
        return False
    except ValueError:
        return False

Upvotes: 3

Related Questions