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

 Lab assignment - 2 Topics: Input, Print, Variables, Conditional Structure, While

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!