'''#*************************************************************************'''
#* Name: Mode-Median-Mean Calculator *#
#* *#
#* Purpose: To calculate the mode, median and mean of a list of numbers *#
#* and the mode of a list of strings because that is what we are *#
#* learning in math atm in school
*#
#* *#
#* Author: William Bryant *#
#* *#
#* Created: 11/09/2013 *#
#* *#
#* Copyright: (c) William 2013 *#
#* *#
#* Licence: IDK :3 *#
'''**************************************************************************'''
#-----# ~~Import things I am using~~ #-----#
# |
# |
# \/
import time
import itertools
#-----# ~~Variables that I am using, including the list.~~ #-----#
# |
# |
# \/
List = []
NumberOfXItems = []
themode = None
themean = None
count = None
#-----# ~~Functions that I am using.~~ #-----#
# |
# |
# \/
def HMNs():
global TheStr, user_inputHMNs, List_input, List
user_inputHMNs = input("You picked string. This program cannot calculate the mean or median, but it can calculate the mode.
How many strings are you using in your list? (Can not be a decimal number) \nEnter: ")
user_inputHMNs
time.sleep(1.5)
TheStr = int(user_inputHMNs)
for i in range(TheStr):
List_input = input("Enter your strings. (One in each input field): ")
List.append(List_input)
print("Your list -> ", List)
if List.count == int(user_inputHMNs):
break
mode()
mean()
print("\n*Mode*:", themode)
print("*Median*:", "<Coming soon!>\n")
print("*Mean*:", themean)
def HMNn():
global TheNum, user_inputHMNn, List_input, List
user_inputHMNn = input("You picked number.
How many numbers are you using in your list? (Can not be a decimal number) \nEnter: ")
user_inputHMNn
time.sleep(1.5)
TheNum = int(user_inputHMNn)
for i in range(TheNum):
List_input = input("Enter your numbers. (One in each input field): ")
List_input = int(List_input)
List.append(List_input)
print("\nYour list -> ", List)
if List.count == int(user_inputHMNn):
break
mode()
mean()
print("\n*Mode*:", themode)
print("*Median*:", "<Coming soon!>")
print("*Mean*:", themean)
def NOS():
while True: # Loops forever (until the break)
answer = input("Does your list contain a number or a string? \nEnter: ")
answer = answer.lower()
if answer in ("string", "str", "s"):
HMNs()
break
elif answer in ("number", "num", "n", "int"):
HMNn()
break
elif answer in ("quit", "q"):
break # Exits the while loop
else:
print("You did not enter a valid field,
Sorry. \nEnter: ")
time.sleep(1.5)
def mean():
global themean
thecount = []
for i in List:
thecount.append(List.count(i))
thesum = sum(List)
thecount = sum(thecount)
themean = thesum / thecount
def mode():
global themode
max_occurrences = 0
themode = None
for i in List:
thecount = List.count(i)
if thecount > max_occurrences:
max_occurrences = thecount
themode = i
#-----# ~~The functions which need calling~~ #-----#
# |
# |
# \/
NOS()