Python coding mutiple elif's - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Python coding mutiple elif's (/thread-20245.html) |
Python coding mutiple elif's - metro17 - Aug-02-2019 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: Can I get help.Thanks RE: Python coding mutiple elif's - metulburr - Aug-02-2019 (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
|