Advertisement
DeaD_EyE

rechnung_beispiel

Feb 16th, 2017
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. from functools import partial
  2. import locale
  3. from decimal import Decimal
  4.  
  5. def rechnung(produkte, mwst, loc='de_DE.utf-8'):
  6.     locale.setlocale(locale.LC_ALL, loc)
  7.     pos_fmt = '{:<5}{:<15}{:>20}'
  8.     sum_fmt = partial(pos_fmt.format, '')
  9.     print(pos_fmt.format('Pos.', 'Produkt', 'Preis'))
  10.     print('-'*40)
  11.     print()
  12.     summe = 0
  13.     for position, element in enumerate(produkte, start=1):
  14.         produkt, preis = element
  15.         fpreis = locale.currency(preis)
  16.         ausgabe = pos_fmt.format(position * 10, produkt, fpreis)
  17.         summe += preis
  18.         print(ausgabe)
  19.     print()
  20.     print('='*40)
  21.     print()
  22.     smwst = summe / 100 * mwst
  23.     netto = summe / (100 + mwst) * 100
  24.     fsumme = locale.currency(summe)
  25.     fmwst = locale.currency(smwst)
  26.     fnetto = locale.currency(netto)
  27.    
  28.     print(sum_fmt('Summe', fsumme))
  29.     print(sum_fmt('Mwst.', fmwst))
  30.     print(sum_fmt('Netto', fnetto))
  31.  
  32. produkte = [
  33.     ('Fön', Decimal('20.00')),
  34.     ('Gitarre', Decimal('1450.99')),
  35.     ('DLSR', Decimal('599.75'))
  36.     ]
  37.  
  38. rechnung(produkte, 19)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement