KnowledgeBoat Logo
|

Computer Applications

Rewrite following code fragments 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

Python Control Flow

3 Likes

Answer

min = 0
max = num
if num < 0 :
    min = num
    max = 0
# compute sum of integers from min to max 
i = min
while i <= max:
    sum += i
    i += 1

Answered By

2 Likes


Related Questions