Computer Science
Rewrite the following code fragment using for loop:
while num > 0 :
print (num % 10)
num = num/10
Related Questions
How are following two code fragments different from one another? Also, predict the output of the following code fragments :
(a)
n = int(input( "Enter an integer:" )) if n > 0 : for a in range(1, n + n ) : print (a / (n/2)) else : print ("Now quiting")
(b)
n = int(input("Enter an integer:")) if n > 0 : for a in range(1, n + n) : print (a / (n/2)) else : print ("Now quiting")
Rewrite the following code fragment using for loop:
i = 100 while (i > 0) : print (i) i -= 3
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
Rewrite following code fragment using while loops :
min = 0 max = num if num < 0 : min = num max = 0 # compute sum of integers # from min to max for i in range(min, max + 1): sum += i