-4
answer = input('Hi! Would you like to say something? (No or Yes)')

if answer == No or no:

    print('Okay then, have a good day!')

elif answer == Yes or yes:

    answertwo = input('What would you like to say?')

    print(answertwo, 'Hmmmmmm, Intresting.')

 **if answer == No or no:
NameError: name 'No' is not defined**
Mat
  • 202,337
  • 40
  • 393
  • 406
  • 1
    `answer == "No"`. There are quotes! – Jean-François Fabre Sep 17 '16 at 16:15
  • 2
    `No` is a variable reference, not a string value. Use `"No"` if you expected it to test the value of `answer` against a string. Also, `or` doesn't work the way you think it does. – Martijn Pieters Sep 17 '16 at 16:15
  • See [How do I test one variable against multiple values?](https://stackoverflow.com/a/15112149); you want to test `if answer in ('No', 'no'):`. Or lowercase the string value first and then test against just `'no'`: `if answer.lower() == 'no':`. – Martijn Pieters Sep 17 '16 at 16:16

1 Answers1

0

I would suggest you using .lower() for every input. This ensures that if some types "nO" or "YeS" it takes the lowercase equivalent. Example:

ui = input("Type \"Hi\"").lower()

Next, you should really add an else option to your code. This is for answers you don't want them to type. This should be held in a while loop Example:

while(True):
    ui = input("Type \"Hi\"").title()
    if(ui == "Hi"):
        print("Hello")
        break
    else:
        print("That isn't a choice!")