66.8k views
4 votes
Convert the given for loop to while loop and find the output of the program assuming the

value entered for num is 15.
num = int (input ("Enter a value"))
sum =0
count=0
for i in range (1, num):
if i%2 == 0:
count += 1
sum += i
print(sum)
print(count)

1 Answer

3 votes

Answer:

Step-by-step explanation:

num = int (input ("Enter a value"))

sum =0

count=0

i = 1

while i < num:

if i%2 == 0:

count += 1

sum += i

i += 1

i += 1

print(sum)

print(count)

The output assuming num is 15 would be

56

7

User Kenaniah
by
4.8k points