Predict the output of the following code- x = 10 y = 0 while x > y: x = x - 4 y += 4 print(x, end=" ")t is the meaning of poet?
Answers
Answered by
2
Refer the attached image.
Explanation:
To find the output, we need to write a program for it.
Program:
# Declaring the variables
x=10
y=0
# While loop
while x>y:
x=x-4
y+=4 # Or, y=y+4
# Printing the value of x
print("Output:",x)
Let us understand the program now.
- The first line is used to declare variables.
- Next, in while loop, the condition is x>y. So,
- 10>0, condition is true, control goes inside the loop. So, x = 10 - 4 = 6, y = 0 + 4 = 4
- 6>4, conduction is true, control goes inside the loop. So, x = 6 - 4 = 2, y = 4 + 4 = 8
- 2>8, condition is false, while loop ends.
- So, at last x value is printed, which is equal to 2.
Refer the attached image for the output.
Attachments:
Similar questions