diff options
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) |
