lundi 2 avril 2018

How do I define blank space in python?

I'm trying to create GUI interface where user needs to enter a value. If he enters it wrong, error message appears. Otherwise it keeps the correct answer. But what if user forgot to enter a value and just left it blank? Or pressed enter without entering anything? How do I call up error message in this case?

Just to keep it simple here is basic example without GUI:

h = int(raw_input("Enter "))

if h >= 10:
    print True
elif h < 10:
    print False
else:
    print "Error"

Idea is that if user did not enter anything, it would print

"Error". However, program just stalls and prints the following: ValueError: invalid literal for int() with base 10: ''

So how do I make python see blank space as value and print "Error" instead?

Aucun commentaire:

Enregistrer un commentaire