Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab assignment - 2 Topics: Input, Print, Variables, Conditional Structure, While Loop Problem Statement: Summation and average of a series of even and odd numbers

image text in transcribed

Lab assignment - 2 Topics: Input, Print, Variables, Conditional Structure, While Loop Problem Statement: Summation and average of a series of even and odd numbers The purpose of this assignment is to gain experience in python's conditional structure and while loop. Lab Scenario: In this assignment, you will design a program that receives a series of even and odd numbers from the user and keep adding the even and odd numbers separately. The program allows the user to type "0" to indicate that s/he is finished providing inputs. After the user presses " 0 " key, the program should print the summation and average of the even and odd numbers separately. You are required to use while loop and conditional statements for this assignment. Lab Procedure: 1. Prior starting of the work consider how to design the while loop: a. What would be the loop condition? b. What would be the stopping criteria? 2. Determine how to calculate the summation and average of the even and odd numbers separately. What are the variables to store the summations and where to initialize the variables? Hint: define a variable named 'total_even' for even numbers and 'total_odd' for odd numbers, initialize them with a value of 0 before while loop and keep adding the even numbers to 'total_even' and the odd numbers to 'total_odd'. Think about the right operator which keeps adding to a variable and the right operator which identify a number is even or odd. 3. How to calculate the average (formula provided below) of even and odd numbers separately? How to obtain the total number of even numbers and the total number of odd numbers. Hint: Think about the variables 'count_odd' and 'count_even'. Average of even numbers = summation of even numbers / total number of even numbers Average of odd numbers = summation of odd numbers / total number of odd numbers 4. Test the application by hand-calculating several values and use the same values to validate the operation. Your code is supposed to calculate the summation and average of even and odd numbers as shown below. Also, don't count " 0 " as an even number when you calculate the average of even numbers. Sample input/output: Enter a non-zero number or type 0 to exit: 8 Enter a non-zero number or type 0 to exit: 20 Enter a non-zero number or type 0 to exit: 15 Enter a non-zero number or type 0 to exit: 50 Enter a non-zero number or type 0 to exit: 35 Enter a non-zero number or type 0 to exit: 5 Enter a non-zero number or type 0 to exit: 42 Enter a non-zero number or type 0 to exit: 0 Summation of even numbers: 80 Summation of add numbers: 45 Average of even numbers: 20.0 Average of odd numbers: 15.0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Flash XML Applications Use AS2 And AS3 To Create Photo Galleries Menus And Databases

Authors: Joachim Schnier

1st Edition

0240809173, 978-0240809175

More Books

Students also viewed these Databases questions

Question

Which form of proof do you find most persuasive? Why?

Answered: 1 week ago