Computer Science, asked by pathanzaid, 4 months ago

What is following code doing? What would it print for input as 3?(2)n = int(input(“Enter an integer:”))if n < 1 :print(“invalid value”)else :for i in range(1,n+1) :print(i* i)​

Attachments:

Answers

Answered by anindyaadhikari13
3

Answer:-

The following code is used to print the squares of the number from 1 to N if and only if N>1 is true.

So,

Here, n=3

So,

n<1 is false.

Else block will execute.

Now, we will move to for loop

At first, i=1, i*i=1

Output:- 1

Then, i=2, i*i=2*2=4

Output:- 4

Now, i=3, i*i=3*3=9

Output:- 9

Hence,output is,

1

4

9

Similar questions