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

There should not be a colon after the function definition.
There should not be a colon after the function definition.

The print statements shall be ended with a semi-colon.
The print statements shall be ended with a semi-colon.

You cannot add a conditional statement after the else keyword.
You cannot add a conditional statement after the else keyword.

There should be a double modulus to check for the remainder.

1 answer

The error in the syntax of the provided code is:

You cannot add a conditional statement after the else keyword.

In Python, the else statement does not take a condition; it should simply be followed by a colon and the block of code to execute if the if condition is not met. The correct syntax should be:

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