Why won't this work?

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

Why wont this work?
<Below this line, add a link to the EXACT exercise that you are stuck at. The query string (? and beyond) may be truncated.>

<In what way does your code behave incorrectly? Include ALL error messages.>
It says “Traceback (most recent call last):
File “python”, line 19, in
NameError: name ‘decision’ is not defined” whenever I run it.
<What do you expect to happen instead?>

```python

while decision != “yes” or decision != “no”:

decision = input("You can still do it, though!  Do you keep going?")

if(decision == "no"):
    print("Good bye. =(")
elif(decision == "yes"):
    print("Awesome!")
else:
    print("Answer again.")
<do not remove the three backticks above>

@linhy1,
In your WHILE-loop condition you are referring to the variable decision which you have not defined…

But there is also the problem of the usage of the comparison operator and the logical operator’ !!
If you use the code

print("##===============================================")
print('##==>> decision != "yes" or decision != "no"')
print("##===============================================")
decision=""
print("decision[{}] \t==> {}".format(
    decision,decision != "yes" or decision != "no"))
decision="yes"
print("decision[{}] \t==> {}".format(
    decision,decision != "yes" or decision != "no"))
decision="no"
print("decision[{}] \t==> {}".format(
    decision,decision != "yes" or decision != "no"))
decision="x"
print("decision[{}] \t==> {}".format(
    decision,decision != "yes" or decision != "no"))
print("##===============================================")
print('##==>> decision == "yes" or decision == "no"')
print("##===============================================")
decision=""
print("decision[{}] \t==> {}".format(
    decision,decision == "yes" or decision == "no"))
decision="yes"
print("decision[{}] \t==> {}".format(
    decision,decision == "yes" or decision == "no"))
decision="no"
print("decision[{}] \t==> {}".format(
    decision,decision == "yes" or decision == "no"))
decision="x"
print("decision[{}] \t==> {}".format(
    decision,decision == "yes" or decision == "no"))
print("##===============================================")
print('##==>> not (decision == "yes" or decision == "no")')
print("##===============================================")
decision=""
print("decision[{}] \t==> {}".format(
    decision,not (decision == "yes" or decision == "no")))
decision="yes"
print("decision[{}] \t==> {}".format(
    decision,not (decision == "yes" or decision == "no")))
decision="no"
print("decision[{}] \t==> {}".format(
    decision,not (decision == "yes" or decision == "no")))
decision="x"
print("decision[{}] \t==> {}".format(
    decision,not (decision == "yes" or decision == "no")))

you would get the OUTPUT

##===============================================
##==>> decision != "yes" or decision != "no"
##===============================================
decision[] 	==> True
decision[yes] 	==> True
decision[no] 	==> True
decision[x] 	==> True
##===============================================
##==>> decision == "yes" or decision == "no"
##===============================================
decision[] 	==> False
decision[yes] 	==> True
decision[no] 	==> True
decision[x] 	==> False
##===============================================
##==>> not (decision == "yes" or decision == "no")
##===============================================
decision[] 	==> True
decision[yes] 	==> False
decision[no] 	==> False
decision[x] 	==> True

and you would see
that the code you are using is creating an infinite-loop as you are never exiting !!!

http://stackoverflow.com/questions/14594522/how-to-break-out-of-while-loop-in-python
http://stackoverflow.com/questions/189645/how-to-break-out-of-multiple-loops-in-python
http://stackoverflow.com/questions/13962471/python-break-function-doesnt-end-while-true

Completely unreadable. Rewrite to:

while not ( ... ):

(Avoid multiple NOT’s in a condition, it doesn’t need to be difficult to read.)

How do you make it uninfinite?

Loops stop when their conditions are no longer satisfied.

If your loop does not stop, then your condition does not get satisfied.

So change the condition, or change what the condition tests.

@linhy1,
apart of what @ionatan wrote
you could make use of the break statement
like

while True:
    decision = input("You can still do it, though!  Do you keep going?")
    
    if(decision == "no"):
        print("Good bye. =(")
        break
    elif(decision == "yes"):
        print("Awesome!")
        break
    else:
        print("Answer again.") 

How do you get it to continue for yes?

@linhy1,
**Q:**How do you get it to continue for yes?
A: Remove the break-statement from the ELIF

Thank you, I’ll try that! :slight_smile: