Computer Science
Predict the output of the following code fragments:
x = 10
y = 0
while x > y:
print (x, y)
x = x - 1
y = y + 1
Python
Python Control Flow
83 Likes
Answer
10 0
9 1
8 2
7 3
6 4
Working
| x | y | Output | Remarks |
|---|---|---|---|
| 10 | 0 | 10 0 | 1st Iteration |
| 9 | 1 | 10 0 9 1 | 2nd Iteration |
| 8 | 2 | 10 0 9 1 8 2 | 3rd Iteration |
| 7 | 3 | 10 0 9 1 8 2 7 3 | 4th Iteration |
| 6 | 4 | 10 0 9 1 8 2 7 3 6 4 | 5th Iteration |
Answered By
31 Likes
Related Questions
Rewrite following code fragment using while loops :
for i in range(4) : for j in range(5): if i + 1 == j or j + 1 == 4 : print ("+", end = ' ') else : print ("o", end = ' ') print()Predict the output of the following code fragments:
count = 0 while count < 10: print ("Hello") count += 1Predict the output of the following code fragments:
keepgoing = True x=100 while keepgoing : print (x) x = x - 10 if x < 50 : keepgoing = FalsePredict the output of the following code fragments:
x = 45 while x < 50 : print (x)