Trying to write a simple if, elif statement. I prompt the user for an input and: if input is an int(), run the if seconds => statement and begin countdown. elif input is a str(), print to the user to input an int().
print("We're ready captain! How many seconds until launch?")
seconds = input()
isInputString = type(seconds) == str #yields True if seconds == str()
if isInputString == True: #tell the user to try again
print("I need a number Captain!")
seconds = input() #prompt a second input
else: #else it wasn't a str() and to proceed on with script
pass
Currently the script will prompt for a second input even if a int() was entered.
Is this due to how I entered my if - else statement?
I feel like it should resort to else - pass if an int() is entered but it still prompts the 2nd branch input() even though isInputString == False.
Aucun commentaire:
Enregistrer un commentaire