Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Python coding mutiple elif's
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)
        elif userInput in question:
                random_response = random.choice(responses)
        elif userInput in question1:
                random_responses1 = random.choice(responses1)
        elif userInput in question2:
                random_responses2 = random.choice(responses2)
                print("I did not understand what you said")
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.
(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
>>> hola hey! >>> How are you doing? I'm fine >>> Your name please? Steve

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  simple if elif conditions in Python Chandan 2 176 Jan-08-2020, 02:36 PM
Last Post: DeaD_EyE
  Whats the right way to refactor this Big if/elif/elif ? pitosalas 1 271 Jul-28-2019, 05:52 PM
Last Post: ichabod801
  if-elif-else coding help esyfilamaj 6 930 Oct-30-2018, 11:45 PM
Last Post: nilamo

Forum Jump:

Users browsing this thread: 1 Guest(s)