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
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
Related questions
Question
Write a
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
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
Knowledge Booster
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.Recommended textbooks for you
Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole
Operations Research : Applications and Algorithms
Computer Science
ISBN:
9780534380588
Author:
Wayne L. Winston
Publisher:
Brooks Cole