CBSE Class 11 Computer Science Question 101 of 161

Flow of Control — Question 10

Back to all questions
10
Question

Question 9b

Rewrite the following code fragment using for loop:

while num > 0 :
    print (num % 10)
    num = num/10

Answer

l = [1]
for x in l:
    l.append(x + 1)
    if num <= 0:
        break
    print (num % 10)
    num = num/10
Answer