Writing Computer Programs Quick Check 1 of 51 of 5 Items Question Identify the error in the syntax of the following code: def is_year(year): if year % 4 == 0: print('Year is divisible by 4') else year % 4 != 0: print('Year is not divisible by 4') (1 point) Responses The print statements shall be ended with a semi-colon. The print statements shall be ended with a semi-colon. There should be a double modulus to check for the remainder. There should be a double modulus to check for the remainder. There should not be a colon after the function definition. There should not be a colon after the function definition. You cannot add a conditional statement after the else keyword. You cannot add a conditional statement after the else keyword. Skip to navigation page 13 of 13

1 answer

The error in the syntax of the provided code is: You cannot add a conditional statement after the else keyword.

The correct way to structure the code would be to use just else: without any condition. The else statement automatically handles the case where the if condition is not met. Here’s the corrected version of the code:

def is_year(year):
    if year % 4 == 0:
        print('Year is divisible by 4')
    else:
        print('Year is not divisible by 4')