I am currently trying to make a maths quiz and I am working on trying to make the program not crash when the user doesn't answer a question(leaving the user input empty).This is what I have so far
useranswer=raw_input("what is 8-5?")
length=len(useranswer)
while length<=0:
useranswer=raw_input("please enter answer")
length=len(useranswer)
if int(useranswer)==3:
print "correct"
else:
print"sorry wrong"
right now I'm using the method of checking the length of the useranswer
using len(useranswer)
to see if there is anything in the input but this only works if i use raw_input
and not with a normalinput
.
I wanted to know if there is any other easier way of checking if the user input is empty with a different method? I have looked for answers from a few other stackoverflow questions but none of them seemed suitable.
Thankyou!