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")
3 Antworten
+ 8
= is assignment
== is comparison for equality
+ 1
(n%2 = 0)
Single equal sign is used to assign value to variable.
For comparison you need double equalsigns:
(n%2 == 0)
+ 1
What a basic mistake I have made