without haste but without rest

[python/계프] 4주차 과제 - 경기 기록 본문

Homework

[python/계프] 4주차 과제 - 경기 기록

JinungKim 2020. 4. 4. 16:13

경기 기록

 

import random


def groups(n, j):
    res = []
    while(True):
        if n - j > 0:
            n -= j
            res.append(j)
        else:
            res.append(n)
            break
    return res


def make_score(n, name, count):
    tmp = []
    for _ in range(n):
        scores = [random.randint(100, 180) for _ in range(count)]
        tmp.append(scores)
    res = list(zip(name, tmp))
    return res


def divide_group(n, total_list, group):
    res = []
    tmp = [0] + group
    order = []
    sum = 0
    for a in tmp:
        sum += a
        order.append(sum)
    for a in range(len(order)-1):
        res.append(total_list[order[a]:order[a+1]])
    return res


def group_sort(list):
    list.sort(key=lambda x:max(x[1]), reverse=True)


def group_print(list, medal=False):
    m = {0: '금메달', 1: '은메달', 2: '동메달'}
    for i, a in enumerate(list):
        best = max(a[1])
        if medal == True and i < 3:
            print('\t[{}] {}점 {} {}'.format(a[0], best, a[1], m[i]))
        else:
            print('\t[{}] {}점 {}'.format(a[0], best, a[1]))


n = int(input('전체 인원수: '))
j = int(input('조당 최대 인원수: '))
name = [chr(x) for x in range(ord('a'), ord('z'))]
group = groups(n, j)    # list
semi_scores = make_score(n, name, 3)
semi_group = divide_group(n, semi_scores, group)
final_list = []
final_name = []

for i, a in enumerate(semi_group):
    print('\n{}조 {}명'.format(i + 1, len(semi_group[i])))
    group_sort(a)
    group_print(a)
    final_list.extend(a[0:2])
    final_name.append(a[0][0])
    if len(a[0:2]) >= 2:
        final_name.append(a[1][0])
        print('\t결승진출: {} {}'.format(a[0][0], a[1][0]))
    else:
        print('\t결승진출: {}'.format(a[0][0]))

print('\n\t결승선수 명단')
group_print(final_list)
print('\n\t결승 기록 (5회 시도)')
final_scores = make_score(len(final_name), final_name, 5)
group_sort(final_scores)
group_print(final_scores, medal=True)

 

 

Comments