2.0k views
0 votes
Identify syntax errors from the following python constructions and rewrite the connected one. (there can be more than one in each statement.

If answer="Y"
total=total+1
else
print("error")

User Franciscod
by
5.0k points

1 Answer

4 votes

Answer:

The syntax errors are:

(1) If answer = "Y"

(2) else

Step-by-step explanation:

Given

The above code snippet

Required

The syntax error

The first syntax error is: If answer = "Y"

When making equality comparison, the == sign is used not =

The "If" must be in lower case

And, colon (:) is appended at the end of the condition.

So, the correction will be:

if answer == "Y":

The second syntax error is: else

Colon (:) must be appended at the end of the condition.

So, the correction is:

else:

The correct code is:

if answer == "Y":

total = total + 1

else:

print("error")

User CJ Thompson
by
5.4k points