You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

12_dataclass_vs_paramètres.py 890 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Exercice: introduire une classe Commande pour
  2. # éviter las répétition des paramètres
  3. # allongé, noisette et sans_sucre
  4. from cuisine import *
  5. def commande_café(allongé, noisette, sans_sucre):
  6. print("Je voudrais un café", end=" ")
  7. if allongé:
  8. print("allongé", end=" ")
  9. else:
  10. print("serré", end=" ")
  11. if noisette:
  12. print("noisette", end=" ")
  13. if sans_sucre:
  14. print("sans sucre", end=" ")
  15. print()
  16. faire_le_café(allongé, noisette, sans_sucre)
  17. servir_café()
  18. def faire_le_café(allongé, noisette, sans_sucre):
  19. avec_sucre = not sans_sucre
  20. if allongé:
  21. rajouter_eau()
  22. if noisette:
  23. rajouter_lait()
  24. if avec_sucre:
  25. rajouter_sucre()
  26. def servir_café():
  27. print("voici")
  28. commande_café(False, False, False)
  29. commande_café(False, True, False)
  30. commande_café(True, True, False)