Q:

python, please tell me whats wrong

python,please help. I want this code to ask someone if they are ok with the grade. if they say yes, it prints good! if they say no, it says oh well! if they dont say yes or no, i want it to print " please enter yes or no" and keep asking them that until they finally say yes or no. This is what i have so far and when i run it and DONT type yes or no, it spams "please enter yes or no" millions of time
theanswer= raw_input("Are you ok with that grade?")
while theanswer:
    if theanswer == ("yes"):
        print ("good!")
        break
    elif theanswer == ("no"):
        print ("oh well")
        break
    else: 
        print "enter yes or no"

what do i need to do so that it works, ive been trying a lot

A:

You need to have a blocking call in your else statement. Otherwise you will have an infinite loop because theanswer will always be true. Like asking for input:
theanswer= raw_input("Are you ok with that grade?")
while theanswer:
    if theanswer == ("yes"):
        print ("good!")
        break
    elif theanswer == ("no"):
        print ("oh well")
        break
    else: 
        theanswer= raw_input("Please enter yes or no")

Here is a good resorce on Blocking vs Non-Blocking I/O. It's an important fundamental in any application.

A:

or this (this separates the input logic from what you do with the answer):
theanswer = raw_input("Are you ok with that grade?")
while theanswer not in ('yes', 'no'):
    theanswer = raw_input('Please enter yes or no')

if theanswer == "yes":
    print("good!")
elif theanswer == "no":
    print("oh well")

