Rewrite following code fragments using while
loops
(a) min = 0
max = num
if num < 0:
min = num
max = 0
# compute sum of integers
from min to max
for 1 in range(min, max + 1):
sum += 1
(b) for i in range(1, 16):
if 1% 3 = @
print(i)
Answers
Answered by
8
Explanation:
(a)
# compute sum of integers from min to max
while min<=max:
sum += 1
min += 1
(b) this code in the question is not the correct one. I assume the question is :
for i in range(1, 16):
if i% 3 == 0:
print(i)
in that case the equivalent while loop version is:
i=1
while i < 16:
if i% 3 == 0:
print(i)
i +=1
Similar questions
Business Studies,
4 months ago
English,
4 months ago
Math,
9 months ago
English,
1 year ago
Accountancy,
1 year ago