TP02
This commit is contained in:
7
TP02.py
7
TP02.py
@@ -3,7 +3,6 @@ from decimal import Decimal, InvalidOperation, ROUND_HALF_UP
|
||||
THRESHOLD = Decimal('200.00')
|
||||
|
||||
def read_amount(prompt: str) -> Decimal | None:
|
||||
"""Demande un montant à l'utilisateur, retourne None si 0 (arrêt)."""
|
||||
while True:
|
||||
s = input(prompt).strip().replace(',', '.')
|
||||
if s == '':
|
||||
@@ -25,20 +24,15 @@ def afficher_stats(montants: list[Decimal]) -> None:
|
||||
if not montants:
|
||||
print("\nAucun chèque saisi pour le moment.\n")
|
||||
return
|
||||
|
||||
count = len(montants)
|
||||
total = sum(montants)
|
||||
moyenne = (total / count).quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)
|
||||
|
||||
bas = [m for m in montants if m < THRESHOLD]
|
||||
haut = [m for m in montants if m >= THRESHOLD]
|
||||
|
||||
bas_count, bas_total = len(bas), sum(bas) if bas else Decimal('0.00')
|
||||
haut_count, haut_total = len(haut), sum(haut) if haut else Decimal('0.00')
|
||||
|
||||
min_montant = min(montants)
|
||||
max_montant = max(montants)
|
||||
|
||||
print("\n--- Récapitulatif ---")
|
||||
print(f"Nombre de chèques : {count}")
|
||||
print(f"Montant total : {total} €")
|
||||
@@ -50,7 +44,6 @@ def afficher_stats(montants: list[Decimal]) -> None:
|
||||
|
||||
def main():
|
||||
montants: list[Decimal] = []
|
||||
|
||||
print("Saisie des chèques — entre 0 pour terminer.")
|
||||
while True:
|
||||
montant = read_amount("Montant du chèque en € (0 pour terminer) : ")
|
||||
|
||||
Reference in New Issue
Block a user