Untitled

mail@pastecode.io avatar
unknown
python
a year ago
873 B
3
Indexable
Never
from collections import Counter


class Student:
    def __init__(self, name, fives, tens, twenties):
        self.name = name
        self.fives = fives
        self.tens = tens
        self.twenties = twenties
    def getCash(self):
        return self.fives*5 + self.tens*10 + self.twenties*20


def most_money(students):
    cash = []
    names = []
    dict_students = {}

    for x in students:
        names.append(x.name)
        cash.append(x.getCash())

    for x in range(len(students)):
        key = names[x]
        value = cash[x]
        dict_students[key] = value

    values = dict_students.values()
    counter = Counter(values)

    if len(students) == 1:
        return students[0].name
    elif len(counter) == 1:
        return 'all'
    else:
        x = max(dict_students, key=dict_students.get)
        return x