This commit is contained in:
johanleroy
2025-09-08 11:25:01 +02:00
parent 63cba376cd
commit cdf563457d
7 changed files with 108 additions and 0 deletions

8
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

10
.idea/ENI-Python.iml generated Normal file
View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.13 (ENI-Python)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

7
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Black">
<option name="sdkName" value="Python 3.13 (ENI-Python)" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.13 (ENI-Python)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/ENI-Python.iml" filepath="$PROJECT_DIR$/.idea/ENI-Python.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

63
TP02.py Normal file
View File

@@ -0,0 +1,63 @@
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 == '':
print("Entrée vide — réessaie.")
continue
try:
d = Decimal(s)
except InvalidOperation:
print("Montant invalide — entre un nombre.")
continue
if d < 0:
print("Le montant ne peut pas être négatif.")
continue
if d == 0:
return None
return d.quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)
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}")
print(f"Moyenne des montants : {moyenne}")
print(f"Chèques < {THRESHOLD} € : {bas_count} (total = {bas_total} €)")
print(f"Chèques >= {THRESHOLD} € : {haut_count} (total = {haut_total} €)")
print(f"Chèque le plus petit : {min_montant}")
print(f"Chèque le plus grand : {max_montant}\n")
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) : ")
if montant is None:
break
montants.append(montant)
afficher_stats(montants)
if __name__ == "__main__":
main()