InterviewSolution
| 1. |
Please help me why the error is coming |
|
Answer» Given code: 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 code: 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 code above, we first stored the value into the variable 'n' using '='. Since we wanted to test the equality of 'n' and '5', we used '=='. |
|