1.

Please help me why the error is coming​

Answer»

Given co‎de:

entered_number = int(input("Enter your number: "))

remainder = entered_number%2

if remainder = 0:

  print("Your number is even.")

else:

  print("Your number is odd.")

Corrected co‎de:

entered number = int(input("Enter your number: "))

remainder = entered_number%2

if remainder == 0:          #corrected line

  print("Your number is even.")

else:

  print("Your number is odd.")

The ERROR was at line 3, where the condition given was remainder = 0.

In Python, when you want to test for equality, the OPERATOR to be used is '==' [double equal to symbols]. Both '=' and '==' are DIFFERENT in Python. '=' is used for storing values while '==' is used to test for equality.

An example:

>>> n = 5

>>> if n == 5:

          print("True")

else:

          print("FALSE")

In the co‎de above, we first stored the value into the variable 'n' using '='. Since we wanted to test the equality of 'n' and '5', we used '=='.



Discussion

No Comment Found