-2

Here is the code. I want to write a different phrase that needs to be printed according to the Q1 response but the program doesn't work properly and prints all the phrases.

print ('Pet animals')
#choose an animal 
print ('A. Dog')
print ('B. Cat')
print ('C. Hamster')
print ('D. Bird')
print ('E. None')
Q1response= input('I have a ')

if(Q1response == "A" or "a"):
    print ('They are so cute')
elif (Q1response == "B" or "b"):
    print ('They are so haughty')
  • I don't understand what do you want. You are expecting the user to answer with 'A', 'a', 'B' or 'b'? What about the other options? – Celius Stingher Oct 05 '19 at 12:09
  • The code above is just the start. I'm writing a phrase for each letter. The point is that when the code is run it prints all the phrases instead of the single phrase that should be printed according to the user's input – Angelo Herath Oct 05 '19 at 14:17

1 Answers1

0

The if conditions always return true. They should look like:

if(Q1response == "A" or Q1response == "a"):

You can convert your inputs to lowercase to make it easier:

Q1response=input('I have a ').strip().lower()
if(Q1response == "a"):
    print ('They are so cute')
elif (Q1response == "b"):
    print ('They are so haughty')
Maurice Meyer
  • 17,279
  • 4
  • 30
  • 47