CBSE Class 11 Computer Science Question 102 of 161

Flow of Control — Question 11

Back to all questions
11
Question

Question 9c

Rewrite the following code fragment using for loop:

while num > 0 :
    count += 1
    sum += num
        num= 2
        if count == 10 :
            print (sum/float(count))
            break

Answer

for i in range(num, 0, -2):
    count += 1
    sum += i
    if count == 10 :
        print (sum/float(count))
        break
Answer