0

What is wrong in this code??

number = int(input ("Enter the number")) if number % 2 = 2 : print ("This is an even no.") else: print ("This is an odd no.")

5th Mar 2022, 5:08 PM
Prince
Prince - avatar
4 Answers
+ 2
Prince number % 2 == 0 single equal (=) is used to assign value not used to compare values. and what about 2? Is it not even number?
5th Mar 2022, 5:12 PM
AÍąJ
AÍąJ - avatar
0
Please explain concept of 2.
5th Mar 2022, 5:20 PM
Prince
Prince - avatar
0
As AJ said it should be 0 Why zero? Do you know what % means?? It calculates the remainder, right. So if we do: print(4%2) then the answer will be zero it means that for any even number the remainder will be zero if we will divide it by 2. That's why we use: ... x%2==0: ...
5th Mar 2022, 5:24 PM
NEZ
NEZ - avatar