Q. Rewrite the following code fragments using for loop:
(a)
i = 10
while (i > 0) :
print (i)
i -= 3
(b)
while num > 0 :
print (num % 10)
num = num / 10
(c)
while (num > 0) :
count += 1
sum += num
num -= 2
if count == 10 :
print ( sum / float(count))
break
Answer =
(a)
for i in range (10,0,-3):
print (i)
(b)
for i in range (n):
print (n % 10)
n = n / 10
if n < 0 :
break
(c)
for i in range (num,0,-2):
print(num)
count += 1
sum += num
if count == 10 :
print ( sum / float(count))
break
In a part the range should be (100,0)??
ReplyDeleteWhere...
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )