summaryrefslogtreecommitdiff
path: root/py03/ex1/ft_score_analytics.py
blob: 71210fb38cb0506b2709376bd99513dc98cb92c5 (plain)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3

import sys


def create_list():
    list_scores = []
    for arg in sys.argv[1:]:
        try:
            list_scores.append(int(arg))
        except ValueError:
            print(f"Skipped '{arg}'")
    if not list_scores:
        for arg in sys.argv[1:]:
            print(f"Invalid parameter: '{arg}'")
        raise ValueError("No scores provided. Usage "
                         "./ft_score_analytics.py <score1> <score2> etc")
    return list_scores


def check_argument_given():
    if not sys.argv[1:]:
        raise ValueError("No scores provided. Usage "
                         "./ft_score_analytics.py <score1> <score2> etc")


def score_processed(list_scores):
    print('Scores processed: ', list_scores)


def compute_total_score(scores):
    total_score = 0
    for score in scores:
        total_score += int(score)
    return total_score


def score_analytics(scores):
    score_processed(scores)
    total_player = len(scores)
    print(f'Total player: {total_player}')
    total_score = compute_total_score(scores)
    print(f'Total score: {total_score}')
    average_score = total_score / total_player
    print(f'Average score: {round(average_score, 2)}')
    highest_score = max(scores)
    print(f'Highest score: {highest_score}')
    lowest_score = min(scores)
    print(f'Lowest score: {lowest_score}')
    score_range = max(scores) - min(scores)
    print(f'Score range: {score_range}')


if __name__ == "__main__":
    print('=== Player Score Analytics ===')
    try:
        check_argument_given()
        scores = create_list()
        score_analytics(scores)
    except ValueError as err:
        print(err)