In this problem, you are given a partially completed program, and you need to update and fill
Question:
In this problem, you are given a partially completed program, and you need to update and fill in the rest of the program to produce the desired output.
This problem performs a simple numerical analysis on a series of randomly generated numbers.
The instructor has provided a file called Lab05P2-FillThisIn.py. Download that file and rename it Lab05P2.py.
- Copy that file into your PyCharm project.
- Change the program header to include your name and the date.
- Replace every "Fill this in" comment with the correct code that will correctly complete the program.
- You should eventually be able to run the program with no errors and produce results like the sample output.
Sample Output:
How many numbers? 7
Entry 1: 32
Entry 2: 87
Entry 3: 65
Entry 4: 16
Entry 5: 15
Entry 6: 10
Entry 7: 61
--------------
Low: 10
High: 87
Total: 286.00
Average: 40.86
Median: 32
For the calculation of the low, high, and total values, you should use a single function to demonstrate your understanding of using Python functions with lists.
- For the calculation of the average, you should use a single-line formula that will either use one or two functions or previous variables in the program.
- Completing the implementation of the median will involve using a method that can sort the list as well as using a specific index to access an element in the list.
Partial Code:
import random
def main():
# List to store numbers
number_list = # TODO: Fill this in - create an empty list
# The user must enter an odd number here.
number_count = int(input('How many numbers? '))
while number_count % 2 != 1: # Check the number is NOT odd
print('Please enter an odd number.')
number_count = int(input('How many numbers? '))
for i in range(number_count):
# Generate a random number between 1-100 inclusive
number = "Fill-this-in"
print(f'Entry {i+1}: {number}')
# TODO: Fill this in
# Make a function call that will append a number to number_list
low = # TODO: Fill this in - Function to get the lowest value in number_list
high = # TODO: Fill this in - Function to get the highest value in number_list
total = # TODO: Fill this in - Function to get the sum of number_list
average = # TODO: Fill this in - Calculation to compute the average of number_list
# The median is the number that is directly in the middle of the
# sorted list. Implement these three steps to get the median:
number_list."Fill-This-In" # TODO: Use a list method to sort the list.
median_index = (len(number_list) - 1) // 2 # This will get the middle index
median = "Fill-This-In" # TODO: Assign the element in number_list with the
# median_index to the variable median.
print('--------------')
print(f'Low: {low}')
print(f'High: {high}')
print(f'Total: {total:.2f}')
print(f'Average: {average:.2f}')
print(f'Median: {median}')
# Call the main function.
main()
Systems analysis and design
ISBN: 978-0136089162
8th Edition
Authors: kenneth e. kendall, julie e. kendall