KnowledgeBoat Logo

Computer Science

Rewrite the adjacent code in python after removing all syntax error(s). Underline each correction done in the code.

30 = To
for K in range(0,To)
IF k%4 == 0:
    print(K * 4)
Else:
    print(K+3).

Python Funda

7 Likes

Answer

The corrected code is shown below:

To = 30 # Correction 1
for K in range(0,To): # Correction 2
    if K % 4 == 0: # Correction 3
        print(K * 4)
    else: # Correction 4
        print(K+3) # Correction 5

Explanation

Correction 1 — Variable should be on left side and literals should be on right side.
Correction 2 — Semi-colon was missing in the for loop syntax.
Correction 3 — if statement should be in lower case.
Correction 4 — else statement should be in lower case.
Correction 5 — Full stop should not be there at the end of print function.

Answered By

2 Likes


Related Questions