Computer Science

Simrat has written a code to input an integer and display its first 10 multiples (from 1 to 10). Her code is having errors. Rewrite the correct code and underline the corrections made.

n = int(input(Enter an integer:)) 
for i in range(1, 11):
m = n * j
print(m; End = '')

Python Control Flow

2 Likes

Answer

n = int(input(Enter an integer:)) # Error 1
for i in range(1, 11): 
m = n * j # Error 2
print(m; End = '') # Error 3

Error 1 — The quotes around the input message are missing.

Error 2 — The for loop body lacks proper indentation, and the loop variable should be 'i' instead of 'j'.

Error 3 — In Python, a comma (,) is used to separate arguments not semicolon (;), and the first letter of end in the print() function should be lowercase.

The corrected code is :

n = int(input("Enter an integer:")) 
for i in range(1, 11):
    m = n * i
    print(m, end = ' ')

Answered By

1 Like


Related Questions