***NEED SOLUTION IN PYTHON ***
1. Create a main function which only gets executed when the file is directly executed
Hint:
def main():
pass
if __name__ == '__main__':
main()
2. Your programs will use a file called scores.txt to store a
bunch of user-provided numbers.
These can be int or float but their values must be between 0 and
100.
Inside the main function, display the current list of numbers to the user and ask if they want to update the list.
If currently no numbers are stored, display a message.
If the user wants to update the number list, provide them with options to do so. (Similar to how the movie programs adds or deletes movies)
Make sure to handle any possible exceptions in this step. Exceptions might occur if the user enters bad inputs or file is missing or cannot be read etc.
3. After they are done with the list of numbers, your program will display the following information about the list of numbers:
1. mean (or average)
2. mode
3. median
4. range
Write 4 different functions called mean, mode, median and range to get perform this task. Each of these functions will take in a list of numbers and return a number back except the range function which will return a tuple containing two numbers (min and max).
You can do a google search to find out the meanings of the 4 terms.
Do not use python's built-in functions to perform these tasks.
Make sure to write documentation and to perform exception handling in all four of these functions.
Below is the screenshot of the code. Comments are given explaining it.


Below are 2 outputs of the code:
1.

2.

Below is the code to copy:
#CODE STARTS HERE=======================
def range_of(li): #Finds min and max
mini=float(li[0])
maxii=float(li[0])
for s in li:
if float(s)<mini: #checks for smallest number
mini = s
if float(s)>float(maxii): #checkd for biggest number
maxii = s
ran = (mini,maxii) #creates tuple
return ran
def median(li): #finds middle number in the list
count =0
for _ in li:
count+=1
if count % 2 == 0: #if length is even
m1 = li[count // 2]
m2 = li[count // 2 - 1]
med = (m1+m2) / 2
else: #if length is odd
med = li[count // 2]
return med
def mode(li): #finds most repeating number
d = dict() #uses dictionary to store frequency
for s in li:
if s in d: #updates dict if number present
d[s] += 1
else: #creates new key if number is not present
d[s] =1
maxi = 0
mod = 0
for key,val in d.items(): #finding the greatest frequency
if val>maxi:
maxi=val
mod = key
return mod
def mean(li): #Finds average of list
count =0
sum_of=0
for s in li:
count+=1 #finds the length
sum_of+= float(s) #finds total sum
return sum_of/count
def main():
with open("scores.txt",'r+') as f_r: #to display the existing values
print("Below are the values in scores.txt")
count =0
for score in f_r:
count+=1
print(score, end="")
if count == 0:
print(" *The file is empty* \n")
f_r.close()
inp = input("Do you want to add scores?[y/n] ") #asking user for input
scores_list = []
scores_list_full = []
if inp.strip().lower()== "y":
print("Enter the numbers below. Enter 'q' to quit.")
while True:
try: #To catch any exceptions during value input by user
s = input()
if s.strip().lower() == "q":
break
if isinstance(s, (int, float)) or float(s)<0 or float(s)>100:
raise Exception
scores_list.append(s)
except: #Prints error message and continues for next input
print("Invalid Input")
continue
try: #To catch any exceptions while writing to the file
with open("scores.txt","a+") as f:
for score in scores_list:
f.write(str(score)+"\n")
except:
print("Error in writing to the file")
with open("scores.txt", 'r+') as f_r:
for score in f_r:
scores_list_full.append(float(score.strip())) #To store all values in the list for processing
scores_list_full.sort()
if len(scores_list_full)==0:
exit()
#function calls for processing the list of numbers
mea = mean(scores_list_full)
mod = mode(scores_list_full)
med = median(scores_list_full)
ran = range_of(scores_list_full)
print("Mean :",mea,"\nMode :",mod,"\nMedian :",med,"\nran :",ran)
if __name__ == '__main__':
main() #this is used to run only when the file is directly executed
#CODE ENDS HERE=========================
***NEED SOLUTION IN PYTHON *** 1. Create a main function which only gets executed when the...
Assignment: USING PYTHON Expected submission: TWO (2) Python files, main.py and HelperClasses.py Make a file called HelperClasses and create a class inside it called Helpers Inside Helpers, create 8 static methods as follows: 1.) Max, Min, Standard_Deviation, Mean a.) Each of these should take a list as a parameter and return the calculated value 2.) Bubble a.) This should take a list as a parameter and return the sorted list 3.) Median a.) This should take a list as a...
Could anyone help add to my python code? I now need to calculate the mean and median. In this programming assignment you are to extend the program you wrote for Number Stats to determine the median and mode of the numbers read from the file. You are to create a program called numstat2.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The...
Questions 1. How to create a comment in python? 2. The way to obtain user input from command line 3. List standard mathematical operators in python and explain them 4. List comparison operators in python 5. Explain while loop. Give example 6. Explain for loop. Give example 7. How to create infinite loop? And how to stop it? 8. Explain a built-in function ‘range’ for ‘for’ loop 9. Explain break statement 10. Explain continue statement 11. Explain pass statement 12....
Simple python assignment Write a menu-driven program for Food Court. (You need to use functions!) Display the food menu to a user (Just show the 5 options' names and prices - No need to show the Combos or the details!) Ask the user what he/she wants and how many of it. (Check the user inputs) AND Use strip() function to strip your inputs. Keep asking the user until he/she chooses the end order option. (You can pass quantity1, quantity2, quantity3,...
In C# Create an “EmployeeDemo” class. It includes three functions: 1. In the main function, the program calls the readData() function to get the data from file and calls the objSort() function to sort the array of objects. Then, the program prompts user to enter the range of current salary that user want to see and display the employee’s information whose current salary is in the range in a descending order. 2. readData(): it reads the workers and managers information...
I need help in Python. This is a two step problem So I have the code down, but I am missing some requirements that I am stuck on. Also, I need help verifying the problem is correct.:) 7. Random Number File Writer Write a program that writes a series of random numbers to a file. Each random number should be in the range of 1 through 500. The application should let the user specify how many random numbers the file...
NOTE: USE PYTHON CS160 Computer Science Lab 14 Working with lists, functions, and files Objective: Work with lists Work with lists in functions Work with files Assignment: Part 1: Write a program to create a text file which contains a sequence of test scores. Ask for scores until the user enters an empty value. This will require you to have the scores until the user enters -1. After the scores have been entered, ask the user to enter a file...
I need help writing these 2 programs please include all the indents :) In this programming challenge you are to create two Python programs: randomwrite.py andrandomread.py. One program, randomwrite.py, is to write a set of random numbers to a file. The second program, randomread.py, is to read a set of random numbers from a file, counts how many were read, displays the random numbers, and displays the total count of random numbers. Random Number File Writer (randomwrite.py) Create a program...
python 2..fundamentals of python 1.Package Newton’s method for approximating square roots (Case Study 3.6) in a function named newton. This function expects the input number as an argument and returns the estimate of its square root. The script should also include a main function that allows the user to compute square roots of inputs until she presses the enter/return key. 2.Convert Newton’s method for approximating square roots in Project 1 to a recursive function named newton. (Hint: The estimate of...
Hi, I need some help finishing the last part of this Python 1 code. The last few functions are incomplete. Thank you. The instructions were: The program has three functions in it. I’ve written all of break_into_list_of_words()--DO NOT CHANGE THIS ONE. All it does is break the very long poem into a list of individual words. Some of what it's doing will not make much sense to you until we get to the strings chapter, and that's fine--that's part of...