Write a program that uses a while loop to enter any number of positive integers. When the loop ends, the program should report the totals of both the even and odd integers. I can't seem to figure out what is wrong with my code.. it is supposed to be the totals of even and odd so evens should be added up and should odds. even_sum = 0 odd_sum = 0 while(True): num = int(input('Enter Positive interger or Enter 0 to quit: '))#prompt user for positive interger if(num == 0): break elif(num%2 == 0): even= even_sum + num else: odd= odd_sum + num print(f'The evens total {even} and the odds total {odd}') #DIsplay number of evens and odd numbers

Operations Research : Applications and Algorithms
4th Edition
ISBN:9780534380588
Author:Wayne L. Winston
Publisher:Wayne L. Winston
Chapter23: Simulation With The Excel Add-in @risk
Section: Chapter Questions
Problem 6RP
icon
Related questions
Question

Write a program that uses a while loop to enter any number of positive integers. When the loop ends, the program should report the totals of both the even and odd integers.

I can't seem to figure out what is wrong with my code.. it is supposed to be the totals of even and odd so evens should be added up and should odds.

even_sum = 0
odd_sum = 0
while(True):
num = int(input('Enter Positive interger or Enter 0 to quit: '))#prompt user for positive interger
if(num == 0):
break
elif(num%2 == 0):
even= even_sum + num
else:
odd= odd_sum + num

print(f'The evens total {even} and the odds total {odd}') #DIsplay number of evens and odd numbers

 

Enter a positive integer or Enter to quit 1
Enter a positive integer or Enter to quit 2
Enter a positive integer or Enter to quit 3
Enter a positive integer or Enter to quit 4
Enter a positive integer or Enter to quit 5
Enter a positive integer or Enter to quit
The evens total 6 and the odds total 9
Transcribed Image Text:Enter a positive integer or Enter to quit 1 Enter a positive integer or Enter to quit 2 Enter a positive integer or Enter to quit 3 Enter a positive integer or Enter to quit 4 Enter a positive integer or Enter to quit 5 Enter a positive integer or Enter to quit The evens total 6 and the odds total 9
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Basics of loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Operations Research : Applications and Algorithms
Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole