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
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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

Transcribed Image Text:**User Input and Totalling of Even & Odd Integers**
_Description: This script is designed to prompt the user for input and then categorizes and totals even and odd integers entered by the user._
**Execution Flow:**
1. Prompt: `Enter a positive integer or Enter to quit`
2. Input #1: `1`
3. Prompt: `Enter a positive integer or Enter to quit`
4. Input #2: `2`
5. Prompt: `Enter a positive integer or Enter to quit`
6. Input #3: `3`
7. Prompt: `Enter a positive integer or Enter to quit`
8. Input #4: `4`
9. Prompt: `Enter a positive integer or Enter to quit`
10. Input #5: `5`
11. Prompt: `Enter a positive integer or Enter to quit`
12. No input (Enter without entering a number)
13. Final Output: `The evens total 6 and the odds total 9`
**Explanation:**
- **User Inputs:** This script requires the user to enter a positive integer every time it prompts "Enter a positive integer or Enter to quit".
- **Categorization:** Each input is analyzed to determine whether it is an even or odd number.
- **Total Calculation:** The script keeps separate running totals for even and odd numbers.
- **Summary Output:** Once the user decides to quit by pressing Enter without typing a number, the script outputs the totals of even and odd numbers.
**Specifics and Calculations:**
- The odd integers entered were 1, 3, and 5.
- The even integers entered were 2 and 4.
- The total for the evens (2 + 4) is 6.
- The total for the odds (1 + 3 + 5) is 9.
This script demonstrates a basic method for collecting user input, categorizing data, and performing arithmetic operations, which are fundamental concepts in programming and computer science education.
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

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education