+ 1

num=20 if num%2=0: print ("number is even") else: if num%2=1: print ("number is odd")

what is the problem ? help!

30th Jan 2018, 11:57 AM
Ritik Khatana
Ritik Khatana - avatar
6 ответов
+ 3
num=20 if (num % 2 = 0) print ("number is even") else if (num % 2 = 1) { print ("number is odd") } else //anything you would like That would be the right way.(You have to put something in the if else if else)
30th Jan 2018, 12:09 PM
Jaime
+ 2
oops sorry for that
30th Jan 2018, 12:13 PM
Jaime
+ 2
According to your code, I think you are trying for even odd checker in Python. In that case you must maintain indent in if and else loop. Check the Below code: num=20; if num%2==0: print("Number is even"); else: print("Number is odd"); //Never forget to mention indent after if and else.
30th Jan 2018, 1:16 PM
Diwakar
Diwakar - avatar
+ 1
@Jaime's solution is right but for comparing two integers you need to use == instead of =, so your program will look something like this num=20 if num%2==0: print("number is even") elif num%2==1: print("number is odd")
30th Jan 2018, 12:12 PM
Jente
+ 1
thanks for helping
30th Jan 2018, 5:12 PM
Ritik Khatana
Ritik Khatana - avatar