CBSE Class 10 Computer Applications
Question 16 of 26
Python Conditionals and Loops — Question 7
Back to all questions 7
Question Question 6
What is following code doing ? What would it print for input as 3 ?
n = input( "Enter an integer:" )
if n < 1 :
print "invalid value"
else :
for i in range(1, n + 1):
print i * iThe code will print the square of each number from 1 till the number given as input by the user if the input value is greater than 0. Output of the code for input as 3 is shown below:
Enter an integer:3
1
4
9