This is not an answer (see @Sukrit Kalra's answer for this), but I see an opportunity to demonstrate how to write cleaner code that I cannot miss. You have a lot of code duplication, which will lead to difficult maintenance of the code in the future. Try instead:
import sys import numpy as np welcomeString = input("Welcome to MMMR Calculator\nWhat would you like to calculate(Mean,Median,Mode,Range):") welcomeString = welcomeString.lower() # Lower once and for all # All averages need to do this numbers = input("What numbers would you like to use?:") numbers = list(map(float, numbers.split(','))) # As per Sukrit Kalra answer # Use a map to get the function you need average_function = { "mean": np.average, "median": np.median, "mode": np.mode, "range": np.arange, } # Print the result of the function by passing in the # pre-formatted numbers from input try: print (average_function[welcomeString](numbers)) except KeyError: sys.exit("You entered an invalid average type!") input() # Remove when you are done with development
Sethmmorton
source share