ISE499: Solving Engineering Problems with Code Homework 4: Frequency Distributions
Page 1 of 4
ISE499: Solving Engineering Problems with Code Homework 4: Frequency Distributions Due: 2/10/2017 @ 11:59PM
Goal For this homework, you will create a program that will continually ask the user for integer values from 1- 10 and will calculate a running total and a running
average. You will also create a frequency distribution which will track the number of occurrences of specific values.
Setup Create a Python file with Spyder called hw04.py. Your hw04.py file must begin with comments in the following format (replace the name and email with your
actual information): ”’ Name ISE499, Spring 2017 USC email Homework 4 ”’ As you become more experienced programmers, these assignments will contain fewer and
fewer implementation details. You have the freedom to solve the assignment in whatever way you see fit – so long as you fulfill the requirements.
Requirements The assignment is broken into several parts – and it is recommended that you proceed in the order given.
Part 1: Setup Create a list of 10 integers and initialize all the values to 0 o The elements of this list will correspond to the number of times the user enters one
of the 10 unique values (1-10)
Part 2: Ask for input Ask the user for a value between 1-10 (inclusive), or enter 0 to stop entering values If the value is anything but 1-10 or 0, produce an
error and ask again Each time the user enters a valid value of 1-10, calculate the running total and the running average and print to the user Increase the correct
list element by 1 based on the user’s input value
Part 3: Output Once the user enters 0, loop through the list and print out a dash character (-) to represent the total number of instances of each number.
Page 2 of 4
Part 4: Repeat Program Lastly, ask the user if they would like to run the entire program again. Continue to repeat the program until the user has entered some form
of “no”.
A Note on Style Be sure to comment your code. Also, you will lose points if your variable names are not meaningful. Make sure you use variable names that correspond to
what you are storing in the variables.
Full Sample Output Below is sample output for a full run-through of the program. As usual, you are not required to be as descriptive as the text below, so long as you
perform and display the required calculations. User input is in red.
Please enter a value 1-10 or 0 to quit: -1 Invalid value! Try again! Please enter a value 1-10 or 0 to quit: 12 Invalid value! Try again! Please enter a value 1-10 or
0 to quit: 1 Total: 1 Average: 1 Please enter a value 1-10 or 0 to quit: 4 Total: 5 Average: 2.5 Please enter a value 1-10 or 0 to quit: 3 Total: 8 Average: 2.66667
Please enter a value 1-10 or 0 to quit: 5 Total: 13 Average: 3.25 Please enter a value 1-10 or 0 to quit: 9 Total: 22 Average: 4.4 Please enter a value 1-10 or 0 to
quit: 5 Total: 27 Average: 4.5 Please enter a value 1-10 or 0 to quit: 6 Total: 33 Average: 4.71429 Please enter a value 1-10 or 0 to quit: 3 Total: 36 Average: 4.5
Please enter a value 1-10 or 0 to quit: 8 Total: 44 Average: 4.88889 Please enter a value 1-10 or 0 to quit: 2 Total: 46 Average: 4.6 Please enter a value 1-10 or 0 to
quit: 6 Total: 52 Average: 4.72727 Please enter a value 1-10 or 0 to quit: 8 Total: 60 Average: 5 Please enter a value 1-10 or 0 to quit: 10 Total: 70 Average: 5.38462
Page 3 of 4
Please enter a value 1-10 or 0 to quit: 10 Total: 80 Average: 5.71429 Please enter a value 1-10 or 0 to quit: 3 Total: 83 Average: 5.53333 Please enter a value 1-10 or
0 to quit: 4 Total: 87 Average: 5.4375 Please enter a value 1-10 or 0 to quit: 6 Total: 93 Average: 5.47059 Please enter a value 1-10 or 0 to quit: 0 1:- 2:- 3:—
4:– 5:– 6:— 7: 8:– 9:- 10:– Again? (Yes/No): yes Please enter a value 1-10 or 0 to quit: 2 Total: 2 Average: 2 Please enter a value 1-10 or 0 to quit: 4 Total: 6
Average: 3 Please enter a value 1-10 or 0 to quit: 3 Total: 9 Average: 3 Please enter a value 1-10 or 0 to quit: 0 1: 2:- 3:- 4:- 5: 6: 7: 8: 9: 10: Again? (Yes/No):
no
Deliverables 1. A compressed folder containing hw04.py, named hw04_lastname_firstname.zip.
Grading Item Points Part 1: Setup 5 Part 2: Ask for Input 10 Part 3: Output 10 Part 4: Repeat Program 5 Total* 30
Page 4 of 4
* Points will be deducted for poor code style, or improper submission.