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 = '')
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 = ' ')
Related Questions
Write
push(rollno)andpop()method in Python:push(rollno)— to add roll number in Stackpop()— to remove roll number from StackWrite the output of the following code with justification if the contents of the file "VIVO.txt" are:
"Welcome to Python Programming!"
F1 = open("VIVO.txt", "r") size = len(F1.read()) print(size) data = F1.read(5) print(data)Given is a Python string declaration:
voice = "Python for All Learners"Write the output of:
print(voice[20 : : -2])Write the output of the code given below:
d1 = {"A" : "Avocado", "B" : "Banana"} d2 = {'B' : 'Bag', 'C' : 'Couch'} d2.update(d1) print(len(d2))