DEV Community

Discussion on: Daily Challenge #121 - Who has the most money?

Collapse
 
peter279k profile image
peter279k

Here is the Python code snippets:

def most_money(students):
    student_name = ''
    sum_student = 0
    check_all = 0
    for student in students:
        current_sum = student.fives * 5 + student.tens * 10 + student.twenties * 20
        if current_sum > sum_student:
            sum_student = current_sum
            student_name = student.name
        elif current_sum == sum_student:
            if check_all == 0:
                check_all += 2
            else:
                check_all += 1

    if check_all == len(students):
        return 'all'

    return student_name