0

Can somebody help me figure out why this is not working?

Can somebody figure out why this is not working. I am trying to enter an input and if it is the input in the if statment then I want it to print out a certain thing. I want to add more if statements if that is possible. I am fine if this way does not work and another way would work better. I tried puting else statments in there ,but that did not work. INPUT = str(input("Input:")) print(INPUT) if INPUT == (("Hi") or ("hi") or ("Hello") or ("hello")): print("\nHello") if INPUT == (("Goodbye") or ("goodbye") or ("Bye") or ("bye")): print("\nBye")

31st May 2018, 1:39 AM
Nate Bowles
8 Answers
+ 1
INPUT = input().lower() if INPUT in['hi', 'hello'] : print("\nComputer:Hello") elif INPUT in['goodbye', 'bye']: print("\nComputer:Bye") else: print('Sorry can you repeat that please')
4th Jun 2018, 1:18 AM
Nate Bowles
+ 3
You would need to do your comparisons like; if INPUT == "Hi" or INPUT == "hi" ... etc: but it may be easier to do something like; if INPUT in ["Hi", "hi", "Hello", "hello"]: or use the lower() method to change INPUT to all lower case so that you don't need to check for each case option. Note you don't need to convert input() to str() as str is what is already returned from input. INPUT = input("Input:").lower() if INPUT in ['hi', 'hello']:
31st May 2018, 1:49 AM
ChaoticDawg
ChaoticDawg - avatar
+ 3
Nate Bowles Can you show your code?
3rd Jun 2018, 11:11 PM
ChaoticDawg
ChaoticDawg - avatar
+ 2
Thanks for the help, and thanks for the extra information.
31st May 2018, 8:34 PM
Nate Bowles
+ 2
also check the indentation after the colon (:) normally an indentation is four spaces from left to right.
2nd Jun 2018, 8:10 PM
Snr Oscar Ghitto
Snr Oscar Ghitto - avatar
+ 1
Yes,you can use multiple if in python multiple else if also by using syntax- muliple if- if(condition 1): statement if(condition 2): stament if(condition3): statement and so on else if syntax- if(condition 1): statement elif(condition 2): stament elif(condition3): statement and so on(and u can also use an else statement at the end, not compulsory) The difference in execution of these syntaxes is that in multiple if even if first condition is satisfied it will check other conditions also while in else if if condition 1 is satisfied then it will not check other statement.
31st May 2018, 1:55 AM
Pulkit Kamboj
Pulkit Kamboj - avatar
+ 1
I have another question, whenever I try to put in more than one input it has an error.(traceback string 1). Can somebody give me an answer to why this happens.
3rd Jun 2018, 11:00 PM
Nate Bowles
0
Instead of putting the if statement within the previous if statement, I would add it after as an elif statement to check the variable's value a second time: INPUT = lower(str(input("Input:"))) print(INPUT) if INPUT == "hi" or INPUT == "hello": print("\nHello") elif INPUT == "goodbye" or INPUT == "bye": print("\nBye") Hope this helped!
31st May 2018, 1:46 AM
Faisal
Faisal - avatar