Computer Science, asked by Skii2, 6 months ago

i want the answer asap

Attachments:

Answers

Answered by DrNykterstein
5

Given the following code of the Python programming language:

____________________________

x = 100

y = 10

for i in range(5):

x = x - 20

y = y * 2

c = x + y

print(x)

print(y)

print(c)

print(y ** x)

print(y % c)

____________________________

First, Let's look at the variables values that has been analysed at the beginning,

Here,

x = 100

y = 10

Second, Analysing the for loop we get to know that,

  • For loop would run for 5 times.

Since the for loop would run for 5 times hence 20 would be subtracted 5 times from x,

So, After the for loop had stopped, we would get, x = 0

∵ x = 100 - 20×5

x = 0

Also, y would be multiplied by 2, 5 times.

First time: 10 × 2 , y = 20

Second time: 20 × 2 , y = 40

Third time: 40 × 2 , y = 80

Fourth time: 80 × 2 , y = 160

Fifth time: 160 × 2 , y = 320

Hence, Value of y after the for loop would be 320.

Last but not the least,

x and y would be added 5 times to c.

First time: c = 80 + 20 = 100

Here, the value of x = 80 and y = 20

Second time: c = 60 + 40 = 100

Here, the value of x = 80 and y = 40

Third time: c = 40 + 80 = 120

Here, the value of x = 40 and y = 80

Fourth time: c = 20 + 160 = 200

Here, the value of x = 20 and y = 160

Fifth time: c = 0 + 320 = 320

Here, the value of x = 0 and y = 320

Hence, the value of c would be 320 after the for loop.

After the for loop, We are given 5 lines,

First 3 lines would just print the value of x , y and c.

4th line, print(y ** x)

After the for loop,

x = 0 , y = 320

So, It would just print, y raised to the power x

⇒ 320^0 = 1

Hence, It would print 1

5th line, print(y % c)

The % operator would return the remainder when y is divided by c.

Here, y = 320 and c = 320

It would print 0

Final Output:

0

320

320

1

0

Similar questions