0

Python conditional problem

What is wrong with this piece of a code? Why does not it work properly? n = int(input()) if (n%2 != 0): print("Weird") elif ((n%2 = 0) and (2<=n<=5)): print("Not Weird") elif ((n%2 = 0) and (6<=n<=20)): print("Weird") else: print("Not Weird")

26th Dec 2023, 9:15 AM
Dariusz Jenek
Dariusz Jenek - avatar
3 Respostas
+ 8
= is assignment == is comparison for equality
26th Dec 2023, 9:18 AM
Lisa
Lisa - avatar
+ 1
(n%2 = 0) Single equal sign is used to assign value to variable. For comparison you need double equalsigns: (n%2 == 0)
26th Dec 2023, 9:27 AM
Allan Prommik
Allan Prommik - avatar
+ 1
What a basic mistake I have made
26th Dec 2023, 10:16 AM
Dariusz Jenek
Dariusz Jenek - avatar