diff options
| author | yctct <yctct@yctct.com> | 2026-06-07 08:59:04 +0200 |
|---|---|---|
| committer | yctct <yctct@yctct.com> | 2026-06-07 08:59:04 +0200 |
| commit | 15115b4c52bfda0d1cca9fa1155beecbb873ec35 (patch) | |
| tree | b3f0975e63eb04dcba732a78ce9bd9abda8acf01 /py03/ex1/ft_score_analytics.py | |
First commit, add all files
Diffstat (limited to 'py03/ex1/ft_score_analytics.py')
| -rwxr-xr-x | py03/ex1/ft_score_analytics.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/py03/ex1/ft_score_analytics.py b/py03/ex1/ft_score_analytics.py new file mode 100755 index 0000000..71210fb --- /dev/null +++ b/py03/ex1/ft_score_analytics.py @@ -0,0 +1,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) |
