如何在 Python 3.3.0 上编程模式

How Do I Program The Mode On Python 3.3.0

我需要帮助尝试在 python 3.3 中编程模式 我已经尝试了大约 2 个小时,这让我很烦恼。 因为我使用的是 3.3,所以我们没有统计模块,这通常是我解决这个问题的方法,我无法在学校计算机上更新它。我的程序应该计算平均值、中值、众数并退出。他们都工作,除了模式。 谁有想法?这会有所帮助! 到目前为止我只有

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":

看看collections.Counter() and its method most_common():

>>> from collections import Counter
>>> lists = [1, 2, 2, 4, 4, 5, 7]
>>> mode = Counter(lists).most_common(1)
>>> mode
[(2, 2)]

您可以在没有任何额外库的情况下执行以下操作:

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