thanks for checking this out. So I am having a few problems.
I can't seem to get the desired output into another file. I am trying to simulate a receipt in a sense to show the description of the item, quantity, item cost, etc.. It doesn't seem to work right and usually puts a negative in there. I know that it has to do with entering a negative number to stop but I am kind of confused on this.
I can't seem to format correctly either. I want to round everything to two decimal places which I know is {:.2f} but, since I am trying to line these up in columns I can't seem to figure this out.
My Code:
def cashRegister():
subTotal = 0
total = 0
salesTax = .085
registerTableHeader = "{0:<15}{1:>35}{2:>10} {3:>10}{4:>10}\n"\
.format('Description', 'Qty', 'Unit Cost',\
'Item Cost', 'Subtotal')
cashRegisterFile.write(str(registerTableHeader))
quantityOfItem = int(input("Enter quantity of item: "))
while(quantityOfItem > 0):
itemDescription = str(input("Enter Item's description: ")[:30])
itemCost = float(input("Enter item's cost: "))
subTotal = quantityOfItem * itemCost
total += subTotal
quantityOfItem = int(input("Enter quantity of item: "))
registerTable = "{0:<15}{1:>35}{2:>10} {3:>10} {4:>10}\n\n"\
.format(itemDescription, quantityOfItem, itemCost, itemCost * \
quantityOfItem, subTotal)
cashRegisterFile.write(str(registerTable))
Desired Output:
Description Qty Unit Cost Item Cost Subtotal
First Item's Description 1 24.99 24.99 24.99
This is the second item's desc 5 2.00 10.00 34.99
This is the third item's descr 10 11.00 110.00 144.99
Sales Tax 13.05
Total 158.04
Thanks for looking at my post!