0

I am in the process of learning Python for my college course and I seem to be stuck. I am attempting to export an expense report output to my lists into a table format. The header information is supposed to be underlined which I cant figure out and the spacing needs to be consistent with the header information. Looking for any recommendations to simplify any coding and how you came to the conclusion. Here is my code to this point:

        #Underlining solutions for spreadsheet_text?
        spreadsheet_text = ["Item","Price","QTY","Total"]
        print(*spreadsheet_text,"\n")
        #List zipping is used to combine multiple lists in one display
        spreadsheet = "\n".join("{:<8} {:^10} {:^6} {:>8}".format(a, b, c, d) for a, b, c, d in list(zip(item_list, item_price_list, quantity_list, total_list)))
        print(spreadsheet,"\n")
        # fee = "\n".join("{:<8} {:>8}".format(a, b) for a, b in list(zip(fee_list, totalofsums_list)))
        # print(fee,"\n")
        # print(totalofsums+fee,"\n")
        print("Commute Fee:", "$",fee,"\n")
        print("Total Sums: $",totalofsums + fee,"\n")
        break
    #Calculator is working. Just need to work on list display.
print("Have a Nice Day!")

Example:

Item    Price     Qty      Total

Item #1 3.5                 2                7.0

Item #2 1.5                 2                3.0

Commute                                      5.0

Total                                        15.0

but in a nice table?

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Where im sure that tabular data would be able to solve this problem fairly easily, I need to be able to format the data in the same areas manually much like I did here: join("{:<8} {:^10} {:^6} {:>8} – James Davis Mar 24 '21 at 23:11
  • Just use Pandas ;-) – DevLounge Mar 24 '21 at 23:12
  • Take a look at this question and answer [Python: String formatter to get underlined headline ](https://stackoverflow.com/questions/55065640/python-string-formatter-to-get-underlined-headline) – itprorh66 Mar 24 '21 at 23:14
  • String formating was what I was looking for to determine left, center, and right aligned. Thank you +1. – James Davis Mar 24 '21 at 23:52

0 Answers0