Skip to main content
Rollback to Revision 2
Source Link
200_success
  • 145.7k
  • 22
  • 191
  • 481
import statistics
import sys

samples = []

def menu():
    print("Welcome to the Statistics Assignment Assistant 3000")

def menu():
   prompt =print("Welcome '''to the Statistics Assistant 3000")
    Selectprint("Select from the following options:")
    1. Find the mean
print("    21. Find the medianmean")
    3. Find the mode
print("    42. Find the rangemedian")
    5. Find the standard deviation
print("    63. Find the z-score
    0. Quit program'''

    def user_choose(mode"):

        print(prompt)
     "   choice =4. input('PickFind one:the 'range")
        choices = {
            '1': find_mean,
            '2': find_median,
            '3': find_mode,
            '4': find_range,
            '5': standard_deviation,
            '6': z_score,
            '0': quit
        }

        if choice in choices:
            choices[choice]print()
"    5. Find the standard else:deviation")
            print("That" isn't one of 6. Find the options"z-score")
            print("Try again")
        "    user_choose()

  0. Quit user_choose(program")
 

def ask_prompt():
   choice print= input("Return"Pick toone: menu?")
    print("[Y/N]")

    user_inputif =choice input== '1':
        find_mean(">)
 "   elif choice == '2':
        find_median()
    user_inputelif choice == '3':
        find_mode()
    elif choice == '4':
        find_range()
    elif choice == '5':
        standard_deviation()
    elif choice == '6':
        z_score()
    elif choice == '0':
        f = user_input.loweropen('sultry.txt')

    if 'n'   for line in user_inputf:
            print("Pressline)
 ENTER to exit..     sys."exit()
    else:
    input    print("That isn't one of the options")
        print("Try again")
        quitmenu()


def load_samples():
    global samples

    print("Would you like to load samples from a text file")
    print("or enter each sample manually?")
    print("    1. File")
    print("    2. Manually")
    print("    3. Return")

    user_response = input("> ")

    if "1" in user_response:

        """This will open default text editor which user will paste or type sample list into"""
        # force_open = os.startfile('sample_list.txt')
        # input("Hit enter when done saving data...")

        withf = open("sample_list.txt") as f:

        samples = f.readlines()
  for line in f:
   samples = [float(x) for x in samples]

        # samples.append(float = [int(line)x) for x in samples]

        return samples

    elif "2" in user_response:

        while True:

            print("Enter a value. Enter 'done' when finished")
            value = input('>')

            try:
                if 'done' in value.lower():
                    print("You entered done")
                    print("Done? [Y/N]")
                    user_response = input("> "">")

                    if 'Y' or 'y' in user:
                        return samples
                        menu()

                else:
                    value = int(value)
                    samples.append(value)

                    print(samples)

            except:
                print("You need to enter an integer")


    elif "3" in user_response:
        menu()

    else:
        print("I don't recognize that option")


def quit():
    print("Than you for using this application")
    sys.exit()


def find_mean():
    global samples

    load_samples()

    mean = round(statistics.mean(samples), 1)
    print("The mean is {}= ".format + str(mean))

    ask_promptprint("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def find_median():
    global samples

    load_samples()

    result = statistics.median(samples)
    print("The median is {}".format(result))
  %s" % ask_prompt(result))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def find_mode():
    global samples

    load_samples()

    result = statistics.mode(samples)
    print("The mode is {}%s" % (result))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.formatlower(result)

    if 'y' in user_input:
        menu()
    ask_promptelse:
        quit()


def find_range():
    global samples

    load_samples()

    x = min(samples)
    y = max(samples)

    result = (y - x)

    print("The range of {}%s and {}%s is {}".format%s" % (x, y, result))

    print("Return to menu?")
    ask_promptprint("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def standard_deviation():
    global samples
    load_samples()

    stan_dev = statistics.stdev(samples)
    print('{:.03}'.format(stan_dev))
    ask_prompt()

    print("Return to menu?")
    print("[Y/N]")

def z_score   user_input = input(">"):
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def z_score():
    global samples
    load_samples()

    printstan_dev = statistics.stdev("Entersamples)
 value to find Z-Score"mean = statistics.mean(samples)
    targetmiddle = int(inputstatistics.median("> ")samples)

    stan_devz = round(statistics.stdev(samples))
  (middle - mean) =/ (statistics.mean(samplesstan_dev), 2)

    z = round((print(target"The Z-Score mean)is /" stan_dev),+ 2str(z))

    print("You"Return choseto {}menu?".format(target))
    print("{}"[Y/N]")
 is the mean".format user_input = input(mean)">")
    print("{} is theuser_input standard= deviation"user_input.formatlower(stan_dev))

    print("Theif Z-Score'y' isin {}".formatuser_input:
        menu(z)
    else:
        quit()

    ask_prompt()

if __name__ == '__main__':
    try:
        menu()
    except:
        print("Press ENTER to exit...")
        input()

Edit: Replaced original with my updated code.

import statistics
import sys

samples = []

def menu():
    print("Welcome to the Statistics Assignment Assistant 3000")

    prompt = '''
    Select from the following options:
    1. Find the mean
    2. Find the median
    3. Find the mode
    4. Find the range
    5. Find the standard deviation
    6. Find the z-score
    0. Quit program'''

    def user_choose():

        print(prompt)
        choice = input('Pick one: ')
        choices = {
            '1': find_mean,
            '2': find_median,
            '3': find_mode,
            '4': find_range,
            '5': standard_deviation,
            '6': z_score,
            '0': quit
        }

        if choice in choices:
            choices[choice]()
        else:
            print("That isn't one of the options")
            print("Try again")
            user_choose()

    user_choose()
 

def ask_prompt():
    print("Return to menu?")
    print("[Y/N]")

    user_input = input("> ")
    user_input = user_input.lower()

    if 'n' in user_input:
        print("Press ENTER to exit...")
        input()
        quit()


def load_samples():
    print("Would you like to load samples from a text file")
    print("or enter each sample manually?")
    print("    1. File")
    print("    2. Manually")
    print("    3. Return")

    user_response = input("> ")

    if "1" in user_response:

        """This will open default text editor which user will paste or type sample list into"""
        # force_open = os.startfile('sample_list.txt')
        # input("Hit enter when done saving data...")

        with open("sample_list.txt") as f:

            for line in f:
                samples.append(float(line))

        return samples

    elif "2" in user_response:

        while True:

            print("Enter a value. Enter 'done' when finished")
            value = input('>')

            try:
                if 'done' in value.lower():
                    print("You entered done")
                    print("Done? [Y/N]")
                    user_response = input("> ")

                    if 'Y' or 'y' in user:
                        return samples
                        menu()

                else:
                    value = int(value)
                    samples.append(value)

                    print(samples)

            except:
                print("You need to enter an integer")


    elif "3" in user_response:
        menu()

    else:
        print("I don't recognize that option")


def quit():
    print("Than you for using this application")
    sys.exit()


def find_mean():
    load_samples()

    mean = round(statistics.mean(samples), 1)
    print("The mean is {} ".format(mean))

    ask_prompt()


def find_median():
    load_samples()

    result = statistics.median(samples)
    print("The median is {}".format(result))
    ask_prompt()


def find_mode():
    load_samples()

    result = statistics.mode(samples)
    print("The mode is {}".format(result))
    ask_prompt()


def find_range():
    load_samples()

    x = min(samples)
    y = max(samples)

    result = (y - x)

    print("The range of {} and {} is {}".format(x, y, result))
    ask_prompt()


def standard_deviation():
    load_samples()

    stan_dev = statistics.stdev(samples)
    print('{:.03}'.format(stan_dev))
    ask_prompt()


def z_score():

    load_samples()

    print("Enter value to find Z-Score")
    target = int(input("> "))

    stan_dev = (statistics.stdev(samples))
    mean = (statistics.mean(samples))

    z = round(((target - mean) / stan_dev), 2)

    print("You chose {}".format(target))
    print("{} is the mean".format(mean))
    print("{} is the standard deviation".format(stan_dev))

    print("The Z-Score is {}".format(z))

    ask_prompt()

if __name__ == '__main__':
    menu()

Edit: Replaced original with my updated code.

import statistics
import sys

samples = []


def menu():
    print("Welcome to the Statistics Assistant 3000")
    print("Select from the following options:")
    print("    1. Find the mean")
    print("    2. Find the median")
    print("    3. Find the mode")
    print("    4. Find the range")
    print("    5. Find the standard deviation")
    print("    6. Find the z-score")
    print("    0. Quit program")

    choice = input("Pick one: ")

    if choice == '1':
        find_mean()
    elif choice == '2':
        find_median()
    elif choice == '3':
        find_mode()
    elif choice == '4':
        find_range()
    elif choice == '5':
        standard_deviation()
    elif choice == '6':
        z_score()
    elif choice == '0':
        f = open('sultry.txt')

        for line in f:
            print(line)
        sys.exit()
    else:
        print("That isn't one of the options")
        print("Try again")
        menu()


def load_samples():
    global samples

    print("Would you like to load samples from a text file")
    print("or enter each sample manually?")
    print("    1. File")
    print("    2. Manually")
    print("    3. Return")

    user_response = input("> ")

    if "1" in user_response:

        # force_open = os.startfile('sample_list.txt')
        # input("Hit enter when done saving data...")

        f = open("sample_list.txt")

        samples = f.readlines()
        samples = [float(x) for x in samples]

        # samples = [int(x) for x in samples]

        return samples

    elif "2" in user_response:

        while True:

            print("Enter a value. Enter 'done' when finished")
            value = input('>')

            try:
                if 'done' in value.lower():
                    print("You entered done")
                    print("Done? [Y/N]")
                    user_response = input(">")

                    if 'Y' or 'y' in user:
                        return samples
                        menu()

                else:
                    value = int(value)
                    samples.append(value)

                    print(samples)

            except:
                print("You need to enter an integer")


    elif "3" in user_response:
        menu()

    else:
        print("I don't recognize that option")


def quit():
    print("Than you for using this application")
    sys.exit()


def find_mean():
    global samples

    load_samples()

    mean = round(statistics.mean(samples), 1)
    print("The mean = " + str(mean))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def find_median():
    global samples

    load_samples()

    result = statistics.median(samples)
    print("The median is %s" % (result))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def find_mode():
    global samples

    load_samples()

    result = statistics.mode(samples)
    print("The mode is %s" % (result))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def find_range():
    global samples

    load_samples()

    x = min(samples)
    y = max(samples)

    result = (y - x)

    print("The range of %s and %s is %s" % (x, y, result))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def standard_deviation():
    global samples
    load_samples()

    stan_dev = statistics.stdev(samples)
    print('{:.03}'.format(stan_dev))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def z_score():
    global samples
    load_samples()

    stan_dev = statistics.stdev(samples)
    mean = statistics.mean(samples)
    middle = statistics.median(samples)

    z = round(((middle - mean) / stan_dev), 2)

    print("The Z-Score is " + str(z))

    print("Return to menu?")
    print("[Y/N]")
    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


if __name__ == '__main__':
    try:
        menu()
    except:
        print("Press ENTER to exit...")
        input()
Replaced code with current version.
Source Link
import statistics
import sys

samples = []

 
def menu():
    print("Welcome to the Statistics Assignment Assistant 3000")
    print("Select from the following options:")
    print("    1. Find the mean")
    print("    2. Find the median")
    print("    3. Find the mode")
    print("    4. Find the range")
    print("    5. Find the standard deviation")
    print("    6. Find the z-score")
    print("    0. Quit program")

    choiceprompt = input("Pick'''
 one   Select from the following options: 
 ")   1. Find the mean
    2. Find the median
    3. Find the mode
    4. Find the range
    5. Find the standard deviation
    6. Find the z-score
    0. Quit program'''

    ifdef user_choose():

        print(prompt)
        choice === '1'input('Pick one: ')
        choices = {
            '1': find_mean(),
    elif choice ==      '2': find_median,
        find_median()    '3': find_mode,
    elif        '4': find_range,
            '5': standard_deviation,
            '6': z_score,
            '0': quit
        }

        if choice ==in '3'choices:
        find_mode    choices[choice]()
    elif choice == '4' else:
        find_range    print("That isn't one of the options")
    elif choice == '5'     print("Try again")
            user_choose()

    user_choose()


def ask_prompt():
    print("Return to menu?")
  standard_deviation  print("[Y/N]") 

    elifuser_input choice= ==input("> '6'")
    user_input = user_input.lower()

    if 'n' in user_input:
        z_scoreprint("Press ENTER to exit...")
    elif choice == '0': input()
        quit()
    else:
        print("That isn't one of the options")
        print("Try again")
        menu()


def load_samples():
    global samples

    print("Would you like to load samples from a text file")
    print("or enter each sample manually?")
    print("    1. File")
    print("    2. Manually")
    print("    3. Return")

    user_response = input("> ")

    if "1" in user_response:

        """This will open default text editor which user will paste or type sample list into"""
        # force_open = os.startfile('sample_list.txt')
        # input("Hit enter when done saving data...")

        f =with open("sample_list.txt")

        samples =as f.readlines()
        samples = [float(x) for x in samples]:

        # samples = [int(x) for xline in samples]f:
                samples.append(float(line))

        return samples

    elif "2" in user_response:

        while True:

            print("Enter a value. Enter 'done' when finished")
            value = input('>')

            try:
                if 'done' in value.lower():
                    print("You entered done")
                    print("Done? [Y/N]")
                    user_response = input(">""> ")

                    if 'Y' or 'y' in user:
                        return samples
                        menu()

                else:
                    value = int(value)
                    samples.append(value)

                    print(samples)

            except:
                print("You need to enter an integer")


    elif "3" in user_response:
        menu()

    else:
        print("I don't recognize that option")


def quit():
    print("Than you for using this application")
    sys.exit()


def find_mean():
    global samples

    load_samples()

    mean = round(statistics.mean(samples), 1)
    print("The mean = " + str(mean))

    print("Returnis to{} menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lowerformat(mean))

    if 'y' in user_input:
        menu()
    else:
        quitask_prompt()


def find_median():
    global samples

    load_samples()

    result = statistics.median(samples)
    print("The median is %s" % (result))

    print("Return to menu?{}")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lowerformat(result)

    if 'y' in user_input:
        menu()
    else:
        quitask_prompt()


def find_mode():
    global samples

    load_samples()

    result = statistics.mode(samples)
    print("The mode is %s" % (result))

    print("Return to menu?{}")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lowerformat(result)

    if 'y' in user_input:
        menu()
    else:
        quitask_prompt()


def find_range():
    global samples

    load_samples()

    x = min(samples)
    y = max(samples)

    result = (y - x)

    print("The range of %s and %s is %s" % (x, y, result))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
 print("The range of {} and {} is menu{}".format()
  x, y, else:result))
        quitask_prompt()


def standard_deviation():
    global samples
    load_samples()

    stan_dev = statistics.stdev(samples)
    print('{:.03}'.format(stan_dev))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quitask_prompt()


def z_score():
    global samples
    load_samples()

    stan_dev = statistics.stdevprint(samples)
  "Enter value meanto =find statistics.mean(samplesZ-Score")
    middletarget = statistics.medianint(samplesinput("> "))

    zstan_dev = round((statistics.stdev(middlesamples))
 -   mean) /= stan_dev(statistics.mean(samples), 2)

    printz = round("The((target Z-Score is "mean) +/ str(zstan_dev), 2)

    print("Return"You tochose menu?{}".format(target))
    print("[Y/N]")
   "{} user_inputis =the inputmean".format(">"mean))
    user_inputprint("{} =is user_inputthe standard deviation".lowerformat(stan_dev))

    if 'y' in user_input:
        menuprint()
    else:
     "The Z-Score is quit{}".format(z))

    ask_prompt()

if __name__ == '__main__':
    try:
        menu()
    except:
        print("Press ENTER to exit...")
        input()

Edit: Replaced original with my updated code.

import statistics
import sys

samples = []

 
def menu():
    print("Welcome to the Statistics Assistant 3000")
    print("Select from the following options:")
    print("    1. Find the mean")
    print("    2. Find the median")
    print("    3. Find the mode")
    print("    4. Find the range")
    print("    5. Find the standard deviation")
    print("    6. Find the z-score")
    print("    0. Quit program")

    choice = input("Pick one: ")

    if choice == '1':
        find_mean()
    elif choice == '2':
        find_median()
    elif choice == '3':
        find_mode()
    elif choice == '4':
        find_range()
    elif choice == '5':
        standard_deviation()
    elif choice == '6':
        z_score()
    elif choice == '0':
        quit()
    else:
        print("That isn't one of the options")
        print("Try again")
        menu()


def load_samples():
    global samples

    print("Would you like to load samples from a text file")
    print("or enter each sample manually?")
    print("    1. File")
    print("    2. Manually")
    print("    3. Return")

    user_response = input("> ")

    if "1" in user_response:

        # force_open = os.startfile('sample_list.txt')
        # input("Hit enter when done saving data...")

        f = open("sample_list.txt")

        samples = f.readlines()
        samples = [float(x) for x in samples]

        # samples = [int(x) for x in samples]

        return samples

    elif "2" in user_response:

        while True:

            print("Enter a value. Enter 'done' when finished")
            value = input('>')

            try:
                if 'done' in value.lower():
                    print("You entered done")
                    print("Done? [Y/N]")
                    user_response = input(">")

                    if 'Y' or 'y' in user:
                        return samples
                        menu()

                else:
                    value = int(value)
                    samples.append(value)

                    print(samples)

            except:
                print("You need to enter an integer")


    elif "3" in user_response:
        menu()

    else:
        print("I don't recognize that option")


def quit():
    print("Than you for using this application")
    sys.exit()


def find_mean():
    global samples

    load_samples()

    mean = round(statistics.mean(samples), 1)
    print("The mean = " + str(mean))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def find_median():
    global samples

    load_samples()

    result = statistics.median(samples)
    print("The median is %s" % (result))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def find_mode():
    global samples

    load_samples()

    result = statistics.mode(samples)
    print("The mode is %s" % (result))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def find_range():
    global samples

    load_samples()

    x = min(samples)
    y = max(samples)

    result = (y - x)

    print("The range of %s and %s is %s" % (x, y, result))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def standard_deviation():
    global samples
    load_samples()

    stan_dev = statistics.stdev(samples)
    print('{:.03}'.format(stan_dev))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def z_score():
    global samples
    load_samples()

    stan_dev = statistics.stdev(samples)
    mean = statistics.mean(samples)
    middle = statistics.median(samples)

    z = round(((middle - mean) / stan_dev), 2)

    print("The Z-Score is " + str(z))

    print("Return to menu?")
    print("[Y/N]")
    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


if __name__ == '__main__':
    try:
        menu()
    except:
        print("Press ENTER to exit...")
        input()
import statistics
import sys

samples = []

def menu():
    print("Welcome to the Statistics Assignment Assistant 3000")

    prompt = '''
    Select from the following options: 
    1. Find the mean
    2. Find the median
    3. Find the mode
    4. Find the range
    5. Find the standard deviation
    6. Find the z-score
    0. Quit program'''

    def user_choose():

        print(prompt)
        choice = input('Pick one: ')
        choices = {
            '1': find_mean,
            '2': find_median,
            '3': find_mode,
            '4': find_range,
            '5': standard_deviation,
            '6': z_score,
            '0': quit
        }

        if choice in choices:
            choices[choice]()
        else:
            print("That isn't one of the options")
            print("Try again")
            user_choose()

    user_choose()


def ask_prompt():
    print("Return to menu?")
    print("[Y/N]") 

    user_input = input("> ")
    user_input = user_input.lower()

    if 'n' in user_input:
        print("Press ENTER to exit...")
        input()
        quit()


def load_samples():
    print("Would you like to load samples from a text file")
    print("or enter each sample manually?")
    print("    1. File")
    print("    2. Manually")
    print("    3. Return")

    user_response = input("> ")

    if "1" in user_response:

        """This will open default text editor which user will paste or type sample list into"""
        # force_open = os.startfile('sample_list.txt')
        # input("Hit enter when done saving data...")

        with open("sample_list.txt") as f:

            for line in f:
                samples.append(float(line))

        return samples

    elif "2" in user_response:

        while True:

            print("Enter a value. Enter 'done' when finished")
            value = input('>')

            try:
                if 'done' in value.lower():
                    print("You entered done")
                    print("Done? [Y/N]")
                    user_response = input("> ")

                    if 'Y' or 'y' in user:
                        return samples
                        menu()

                else:
                    value = int(value)
                    samples.append(value)

                    print(samples)

            except:
                print("You need to enter an integer")


    elif "3" in user_response:
        menu()

    else:
        print("I don't recognize that option")


def quit():
    print("Than you for using this application")
    sys.exit()


def find_mean():
    load_samples()

    mean = round(statistics.mean(samples), 1)
    print("The mean is {} ".format(mean))

    ask_prompt()


def find_median():
    load_samples()

    result = statistics.median(samples)
    print("The median is {}".format(result))
    ask_prompt()


def find_mode():
    load_samples()

    result = statistics.mode(samples)
    print("The mode is {}".format(result))
    ask_prompt()


def find_range():
    load_samples()

    x = min(samples)
    y = max(samples)

    result = (y - x)

    print("The range of {} and {} is {}".format(x, y, result))
    ask_prompt()


def standard_deviation():
    load_samples()

    stan_dev = statistics.stdev(samples)
    print('{:.03}'.format(stan_dev))
    ask_prompt()


def z_score():

    load_samples()

    print("Enter value to find Z-Score")
    target = int(input("> "))

    stan_dev = (statistics.stdev(samples))
    mean = (statistics.mean(samples))

    z = round(((target - mean) / stan_dev), 2)

    print("You chose {}".format(target))
    print("{} is the mean".format(mean))
    print("{} is the standard deviation".format(stan_dev))

    print("The Z-Score is {}".format(z))

    ask_prompt()

if __name__ == '__main__':
    menu()

Edit: Replaced original with my updated code.

deleted 103 characters in body
Source Link
import statistics
import sys

samples = []


def menu():
    print("Welcome to the Statistics Assistant 3000")
    print("Select from the following options:")
    print("    1. Find the mean")
    print("    2. Find the median")
    print("    3. Find the mode")
    print("    4. Find the range")
    print("    5. Find the standard deviation")
    print("    6. Find the z-score")
    print("    0. Quit program")

    choice = input("Pick one: ")

    if choice == '1':
        find_mean()
    elif choice == '2':
        find_median()
    elif choice == '3':
        find_mode()
    elif choice == '4':
        find_range()
    elif choice == '5':
        standard_deviation()
    elif choice == '6':
        z_score()
    elif choice == '0':
        f = open('sultry.txt')

        for line in f:
            print(line)
        sys.exitquit()
    else:
        print("That isn't one of the options")
        print("Try again")
        menu()


def load_samples():
    global samples

    print("Would you like to load samples from a text file")
    print("or enter each sample manually?")
    print("    1. File")
    print("    2. Manually")
    print("    3. Return")

    user_response = input("> ")

    if "1" in user_response:

        # force_open = os.startfile('sample_list.txt')
        # input("Hit enter when done saving data...")

        f = open("sample_list.txt")

        samples = f.readlines()
        samples = [float(x) for x in samples]

        # samples = [int(x) for x in samples]

        return samples

    elif "2" in user_response:

        while True:

            print("Enter a value. Enter 'done' when finished")
            value = input('>')

            try:
                if 'done' in value.lower():
                    print("You entered done")
                    print("Done? [Y/N]")
                    user_response = input(">")

                    if 'Y' or 'y' in user:
                        return samples
                        menu()

                else:
                    value = int(value)
                    samples.append(value)

                    print(samples)

            except:
                print("You need to enter an integer")


    elif "3" in user_response:
        menu()

    else:
        print("I don't recognize that option")


def quit():
    print("Than you for using this application")
    sys.exit()


def find_mean():
    global samples

    load_samples()

    mean = round(statistics.mean(samples), 1)
    print("The mean = " + str(mean))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def find_median():
    global samples

    load_samples()

    result = statistics.median(samples)
    print("The median is %s" % (result))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def find_mode():
    global samples

    load_samples()

    result = statistics.mode(samples)
    print("The mode is %s" % (result))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def find_range():
    global samples

    load_samples()

    x = min(samples)
    y = max(samples)

    result = (y - x)

    print("The range of %s and %s is %s" % (x, y, result))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def standard_deviation():
    global samples
    load_samples()

    stan_dev = statistics.stdev(samples)
    print('{:.03}'.format(stan_dev))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def z_score():
    global samples
    load_samples()

    stan_dev = statistics.stdev(samples)
    mean = statistics.mean(samples)
    middle = statistics.median(samples)

    z = round(((middle - mean) / stan_dev), 2)

    print("The Z-Score is " + str(z))

    print("Return to menu?")
    print("[Y/N]")
    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


if __name__ == '__main__':
    try:
        menu()
    except:
        print("Press ENTER to exit...")
        input()
import statistics
import sys

samples = []


def menu():
    print("Welcome to the Statistics Assistant 3000")
    print("Select from the following options:")
    print("    1. Find the mean")
    print("    2. Find the median")
    print("    3. Find the mode")
    print("    4. Find the range")
    print("    5. Find the standard deviation")
    print("    6. Find the z-score")
    print("    0. Quit program")

    choice = input("Pick one: ")

    if choice == '1':
        find_mean()
    elif choice == '2':
        find_median()
    elif choice == '3':
        find_mode()
    elif choice == '4':
        find_range()
    elif choice == '5':
        standard_deviation()
    elif choice == '6':
        z_score()
    elif choice == '0':
        f = open('sultry.txt')

        for line in f:
            print(line)
        sys.exit()
    else:
        print("That isn't one of the options")
        print("Try again")
        menu()


def load_samples():
    global samples

    print("Would you like to load samples from a text file")
    print("or enter each sample manually?")
    print("    1. File")
    print("    2. Manually")
    print("    3. Return")

    user_response = input("> ")

    if "1" in user_response:

        # force_open = os.startfile('sample_list.txt')
        # input("Hit enter when done saving data...")

        f = open("sample_list.txt")

        samples = f.readlines()
        samples = [float(x) for x in samples]

        # samples = [int(x) for x in samples]

        return samples

    elif "2" in user_response:

        while True:

            print("Enter a value. Enter 'done' when finished")
            value = input('>')

            try:
                if 'done' in value.lower():
                    print("You entered done")
                    print("Done? [Y/N]")
                    user_response = input(">")

                    if 'Y' or 'y' in user:
                        return samples
                        menu()

                else:
                    value = int(value)
                    samples.append(value)

                    print(samples)

            except:
                print("You need to enter an integer")


    elif "3" in user_response:
        menu()

    else:
        print("I don't recognize that option")


def quit():
    print("Than you for using this application")
    sys.exit()


def find_mean():
    global samples

    load_samples()

    mean = round(statistics.mean(samples), 1)
    print("The mean = " + str(mean))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def find_median():
    global samples

    load_samples()

    result = statistics.median(samples)
    print("The median is %s" % (result))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def find_mode():
    global samples

    load_samples()

    result = statistics.mode(samples)
    print("The mode is %s" % (result))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def find_range():
    global samples

    load_samples()

    x = min(samples)
    y = max(samples)

    result = (y - x)

    print("The range of %s and %s is %s" % (x, y, result))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def standard_deviation():
    global samples
    load_samples()

    stan_dev = statistics.stdev(samples)
    print('{:.03}'.format(stan_dev))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def z_score():
    global samples
    load_samples()

    stan_dev = statistics.stdev(samples)
    mean = statistics.mean(samples)
    middle = statistics.median(samples)

    z = round(((middle - mean) / stan_dev), 2)

    print("The Z-Score is " + str(z))

    print("Return to menu?")
    print("[Y/N]")
    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


if __name__ == '__main__':
    try:
        menu()
    except:
        print("Press ENTER to exit...")
        input()
import statistics
import sys

samples = []


def menu():
    print("Welcome to the Statistics Assistant 3000")
    print("Select from the following options:")
    print("    1. Find the mean")
    print("    2. Find the median")
    print("    3. Find the mode")
    print("    4. Find the range")
    print("    5. Find the standard deviation")
    print("    6. Find the z-score")
    print("    0. Quit program")

    choice = input("Pick one: ")

    if choice == '1':
        find_mean()
    elif choice == '2':
        find_median()
    elif choice == '3':
        find_mode()
    elif choice == '4':
        find_range()
    elif choice == '5':
        standard_deviation()
    elif choice == '6':
        z_score()
    elif choice == '0':
        quit()
    else:
        print("That isn't one of the options")
        print("Try again")
        menu()


def load_samples():
    global samples

    print("Would you like to load samples from a text file")
    print("or enter each sample manually?")
    print("    1. File")
    print("    2. Manually")
    print("    3. Return")

    user_response = input("> ")

    if "1" in user_response:

        # force_open = os.startfile('sample_list.txt')
        # input("Hit enter when done saving data...")

        f = open("sample_list.txt")

        samples = f.readlines()
        samples = [float(x) for x in samples]

        # samples = [int(x) for x in samples]

        return samples

    elif "2" in user_response:

        while True:

            print("Enter a value. Enter 'done' when finished")
            value = input('>')

            try:
                if 'done' in value.lower():
                    print("You entered done")
                    print("Done? [Y/N]")
                    user_response = input(">")

                    if 'Y' or 'y' in user:
                        return samples
                        menu()

                else:
                    value = int(value)
                    samples.append(value)

                    print(samples)

            except:
                print("You need to enter an integer")


    elif "3" in user_response:
        menu()

    else:
        print("I don't recognize that option")


def quit():
    print("Than you for using this application")
    sys.exit()


def find_mean():
    global samples

    load_samples()

    mean = round(statistics.mean(samples), 1)
    print("The mean = " + str(mean))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def find_median():
    global samples

    load_samples()

    result = statistics.median(samples)
    print("The median is %s" % (result))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def find_mode():
    global samples

    load_samples()

    result = statistics.mode(samples)
    print("The mode is %s" % (result))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def find_range():
    global samples

    load_samples()

    x = min(samples)
    y = max(samples)

    result = (y - x)

    print("The range of %s and %s is %s" % (x, y, result))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def standard_deviation():
    global samples
    load_samples()

    stan_dev = statistics.stdev(samples)
    print('{:.03}'.format(stan_dev))

    print("Return to menu?")
    print("[Y/N]")

    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


def z_score():
    global samples
    load_samples()

    stan_dev = statistics.stdev(samples)
    mean = statistics.mean(samples)
    middle = statistics.median(samples)

    z = round(((middle - mean) / stan_dev), 2)

    print("The Z-Score is " + str(z))

    print("Return to menu?")
    print("[Y/N]")
    user_input = input(">")
    user_input = user_input.lower()

    if 'y' in user_input:
        menu()
    else:
        quit()


if __name__ == '__main__':
    try:
        menu()
    except:
        print("Press ENTER to exit...")
        input()
deleted 5 characters in body; edited tags; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238
Loading
Source Link
Loading