I'm trying to develop a program that takes an number of inputs from a user then counts the particular number of times that number has been entered by the user then using that information decide what is the most common.
from collections import Counter
results = []
while len(results)<7:
entered=int(raw_input('enter results:'))
results.append(entered)
print results
distribution = Counter(results)
print distribution
it will output something like this:
enter results:1
enter results:2
enter results:3
enter results:2
enter results:6
enter results:5
enter results:4
[1, 2, 3, 2, 6, 5, 4]
Counter({2: 2, 1: 1, 3: 1, 4: 1, 5: 1, 6: 1})
from here i want to be able to take the information given at the end and tell the user which i the most common, i know the user can see it from the counter output, but its part of a task i have been given. i was thinking about using some along the lines of
if 2 >= 4:
print 'most common.'
Aucun commentaire:
Enregistrer un commentaire