solution_074.py

#!/usr/bin/python3
# ===================================================================
# Letter/Invoice
# brute force method with f-strings
# ===================================================================

from datetime import date

pagewidth = 76

customerid = '00054619'

invoiceid  = '00001'

fromaddr   = ['ABC Parts Company',
              'Dept 001',
              '2121 Parts Rd',
              'Parts, OH  91234' ]

toaddr     = ['Flying Machines',
              '120 Airport Ave',
              'Billings, MT  78912' ]

items      = [
             ['Flux Capacitor', 123.47, 3],
             ['Glow sticks', 0.99, 100],
             ['Lightsaber', 105.00, 1]
             ]

# ---- debugging support function

def display_columns():
    print('         1         2         3         4' +
          '         5         6         7         8')
    print('1234567890'*8)

# --------------------------------------------------------------------
# ---- main
# --------------------------------------------------------------------

today = date.today().strftime('%B %d, %Y')

print(f'customer id: {customerid}' +
      f'{" "*(pagewidth - 13 - len(customerid) - len(today))}' +
      f'{today}')

print(f'invoice id : {invoiceid}')

print()

first = True
for a in fromaddr:
    if first:
        first = False
        print(f'From : {a}')
    else:
        print(f'       {a}')
print()
first = True
for a in toaddr:
    if first:
        first = False
        print(f'To   : {a}')
    else:
        print(f'       {a}')

print()
print('Enclosed are the parts you requested.')

print()
print('Item   Description                      Unit Cost      ' +
      'Qty        Total Cost')
print(f'{"-"*4}   {"-"*28}   {"-"*11}    {"-"*5}   {"-"*15}')

print()
ttotal = 0.0
for i,itm in enumerate(items):

    total = round(itm[1]*itm[2],2)
    ttotal += total
    print(f'{i+1:>4}    {itm[0]:27}    {itm[1]:>10.2f}     ' +
          f'{itm[2]:>4}    {total:>14}')

print()
ttstr = f'Total  {str(round(ttotal,2))}'
print(f'{" "*(pagewidth-len(ttstr))}{ttstr}')

print()
print()
print('To return any item please contact our support services at')
print('800-800-8800, M-F 8am to 6pm PST.')