Beispiele und Musterlösungen
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.

big_money.py 650B

2 months ago
123456789101112131415161718192021222324
  1. # Ausgabe von Geldbeträgen in einer speziellen Formatierung
  2. def main():
  3. for money in [100123345, 100123305, 5]:
  4. print(format_money_string(money))
  5. # Funktion zur Formatierung von Geldbeträgen
  6. def format_money_string(cents):
  7. euros = cents // 100
  8. cents = cents % 100
  9. thousands = euros // 1000
  10. euros = euros % 1000
  11. millions = thousands // 1000
  12. thousands = thousands % 1000
  13. if millions > 0:
  14. return f'{millions}.{thousands:03}.{euros:03},{cents:02}'
  15. elif thousands > 0:
  16. return f'{thousands}.{euros:03},{cents:02}'
  17. else:
  18. return f'{euros},{cents:02}'
  19. # Start des Programms
  20. main()