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

Answers

There are no human answers yet.
Answered by GPT-4o mini
The error in the syntax of the code is in the `else` statement. The correct syntax does not require a condition after `else`. Here’s the corrected version:

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

So the specific error is that the line `else year % 4 != 0:` is incorrect; it should simply be `else:` without the condition.

Related Questions