+ 2
python
a = 19 if a < 12: print("Good morning..") elif a >= 12 <= 18: # the shortcut is not working if i do like that a >= 12 and a<= 18: its working fine print("Good evening") else: print("Good night")
7 Answers
+ 4
suppose a = 14,
then
14 <= 12 <= 18 is False
12 <= 14 <= 18 is True
+ 5
if a = 19
then the condition would need to be
12 <= a <= 18
+ 4
Amol Bhandekar ,
my code sample was not correct - sorry. since Lisa has already posted the correct version, i have deleted mine.
+ 3
Amol Bhandekar
If you want to check two conditions logical operator is needed...
+ 3
Thanks all of you :)
Please correct me if I'm wrong the both statements are same or correct just we have changed writing style
elif a <= 12 <= 18:
elif 12 <= a <= 18
+ 1
Thanks @lisa understood :)
0
elif 12<= a <= 18 :