Python Forum

Full Version: Python coding mutiple elif's
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Newbie to Python.
Got this code from this forum.Tried extending it but it is not working.

Code I am running:
import random
greetings = ['hola', 'hello', 'hi', 'Hi', 'hey!','hey']

question = ['How are you?','How are you doing?']
responses = ['Okay',"I'm fine"]

question1 = ['Your name please?','Can I have your name?']
responses1 = ['My name is Steve',"Steve"]

question2 = ['Your age please?','Can I have your age?']
responses2 = ['My age is 24',"24"]

while True:
        userInput = input(">>> ")
        if userInput in greetings:
                random_greeting = random.choice(greetings)
                print(random_greeting)
        elif userInput in question:
                random_response = random.choice(responses)
                print(random_response)
        elif userInput in question1:
                random_responses1 = random.choice(responses1)
                print(random_responses1)
        elif userInput in question2:
                random_responses2 = random.choice(responses2)
                print(random_responses2)
        else:
                print("I did not understand what you said")
Output:
Output:
hola Hi How are you doing? I'm fine Your name please? I did not understand what you said <-------- Its not printing --- 'My name is Steve' OR "Steve"
Can I get help.
Thanks
(Aug-02-2019, 10:12 AM)metro17 Wrote: [ -> ]Its not printing --- 'My name is Steve' OR "Steve"
You must not of put what you said you put in (there isnt even the >>> for your prompt in your output).

This is what i get
Output:
>>> hola hey! >>> How are you doing? I'm fine >>> Your name please? Steve