Search code examples
pythonmathmode

How Do I Program The Mode On Python 3.3.0


I need help trying to program the mode in python 3.3 I've been trying for about 2 hours and it's bugging me. Because I'm using 3.3, so we have no statistics module, which is normally how I would get around this and I can't update as its on school computers. My program Is Supposed to Calculate the Average, Median, Mode And Also Quit. They All Work Except The mode. Anyone Have Any Ideas? It Would Help! All I Have so Far is

lists = [1, 2, 3, 4, 5] 
print("Hello! What Is Your Name?")
name = input()
func = ["Average", "Median", "Quit", "Mode"]
print("Please Enter 5 Numbers")
lists[0] = input()
lists[1] = input()
lists[2] = input()
lists[3] = input()
lists[4] = input()
print("Hello " + name + ", Would You Like " + func[0] + ", " + func[1] + ", " + func[2] + " Or, Would You Like to " + func[3]) 
func1 = input()
if func1 == "Average" :
    total = int(lists[0]) + int(lists[1]) + int(lists[2]) + int(lists[3])
    total1 = total / 4
     print("Your Average is " + str(total1))
elif func1 == "Median" :
    lists.sort()
    print("Your Median Is " + lists[2] + "!")
elif func1 == "Quit":
    print("Thank You")
elif func1 == "Mode":

Solution

  • You can do the following without any additional library:

    lists = [1, 2, 2, 4, 4, 5, 7]
    print(max(set(lists), key=lists.count))