0

Why it is not working for else??

input () hi=True hello=True Hi=True Hello=True if True: print ("Hello sir how can I help you") else: print ("Sorry for inconvinence sir ,please put something valid") input ()

20th Dec 2020, 5:25 AM
Dedipyaman Bhattacharjee
Dedipyaman Bhattacharjee - avatar
6 Answers
+ 3
Is this what you were trying to achieve. greeting = input() greetings = ['hi','hello','Hi','Hello'] if greeting in greetings: print ("Hello sir how can I help you") else: print ("Sorry for inconvinence sir ,please put something valid") You needed to create a valid input and refer it to a list of acceptable responses to activate your if / else conditions
20th Dec 2020, 6:12 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 4
Dedipyaman Bhattacharjee What you actually want to achieve with this. Since you have given the condition as true in the if statement that means that it will always execute only the if part and never the else part. It you write *if False:* then it will always execute the else part because the condition is false
20th Dec 2020, 5:50 AM
Krish
Krish - avatar
+ 1
Thanks
20th Dec 2020, 6:19 AM
Dedipyaman Bhattacharjee
Dedipyaman Bhattacharjee - avatar
0
So what should be given
20th Dec 2020, 5:32 AM
Dedipyaman Bhattacharjee
Dedipyaman Bhattacharjee - avatar