Question: Please edit the following python code to result functionally. No input function, please do not copy other provided answers. Prompt: Write a program that calculates
Please edit the following python code to result functionally. No input function, please do not copy other provided answers.
Prompt:
Write a program that calculates some basic statistics from a set of sales using a function called calstats() that takes the sales as parameters, calculates the min, max, range, and average, and prints the output as shown below. Ensure that all inputs are entered as numbers. In addition, make sure that the correct number of arguments are provided (there should be 5 inputs).
Input:
a) python C:\Users eda\DataProgramming\M4\assign4-12.py 200 100 50 600 300
b) python C:\Users eda\DataProgramming\M4\assign4-12.py 100 700 300
c) python C:\Users eda\DataProgramming\M4\assign4-12.py 100 700 300 test 500
Output:
a) Min: 50 Max: 600 Range: 550 Average: 250
b) The wrong number of sales provided.
c) All inputs should be numeric.
Python code:
import sys
def calstats(sales): if len(sales) != 5: print("The wrong number of sales provided.") return try: sales = float(round(sales1+sales2+sales3+sales4+sales5, 2)) except ValueError: print("All inputs should be numeric.") return min_sale = min(sales) max_sale = max(sales) range_sale = max_sale - min_sale avg_sale = sum(sales) / len(sales) sales1 = int(sys.argv[1]) sales2 = int(sys.argv[2]) sales3 = int(sys.argv[3]) sales4 = int(sys.argv[4]) sales5 = int(sys.argv[5]) print("Min: "+str(min_sale)) print("Max: "+str(max_sale)) print("Range: "+str(range_sale)) print("Average: "+str(avg_sale))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
