@acwoss/

EachTurboPagerecognition

Python

No description

fork
loading
Files
  • main.py
  • data.txt
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
output = '''
ACME Inc.               Uso do espaço em disco pelos usuários
------------------------------------------------------------------------
Nr.  Usuário        Espaço utilizado     % do uso

{usuarios}

Espaço total ocupado: {total:.2f} MB
Espaço médio ocupado: {media:.2f} MB
'''

def format_user_info(i, name, space, total):
    percentage = 100*space/total
    return f'{i: <5}{name: <12}{space: >10.2f} MB{percentage: >18.2f}%'

users = []

with open('data.txt') as stream:
    for line in stream:
        name, space = line.strip().split(' ', 1)
        users.append((name, int(space)/1024**2))

total = sum(user[1] for user in users)
media = total / len(users)

users = [
    format_user_info(i, name, space, total) 
        for i, (name, space) in enumerate(users, 1)
]

print(output.format(usuarios='\n'.join(users), total=total, media=media))