The code given below accepts five numbers and displays whether they are even or odd:
Observe the following code carefully and rewrite it after removing all syntax and logical errors.
Underline all the corrections made.
def EvenOdd()
for i in range(5):
num=int(input("Enter a number"
if num/2==0:
print("Even")
else:
print("Odd")
EvenOdd()
Refined Code:
def EvenOdd(): # Colon added to function definition
for i in range(5): # No modification
num = int(input("Enter a number: ")) # Colon and closing parenthesis added to input
if num % 2 == 0: # Division '/' replaced with modulus '%' for parity check
print("Even") # No modification
else:
print("Odd") # No modification
EvenOdd() # No modification
Modifications Implemented:
: was appended to the function definition def EvenOdd().input("Enter a number: ") by adding a colon and closing the parenthesis.if num / 2 == 0 to if num % 2 == 0 by substituting the division operator / with the modulus operator %.