Syntax error | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Syntax error

Can someone explain why the <= is invalid in the following code: year = int(input("enter birth year")) if year >= 1983 and <= 2000: print("You're a millenial'") else: print("Oldie but goodie")

5th Dec 2018, 6:21 PM
Steve Fernandez
Steve Fernandez - avatar
3 Answers
+ 14
if year >= 1983 and year <= 2000: or if 1983 <= year <= 2000:
5th Dec 2018, 6:26 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 3
Mert Yazıcı Thanks for mentioning both; I totally didn't realize the comparisons / inequality tests could be chained like that. ref: https://docs.python.org/3/reference/expressions.html#comparisons "Comparisons can be chained arbitrarily..."
5th Dec 2018, 7:05 PM
Kirk Schafer
Kirk Schafer - avatar
0
Ah rookie mistake, thanks Mert Yazici!
5th Dec 2018, 6:32 PM
Steve Fernandez
Steve Fernandez - avatar