Dec-01-2017, 01:51 AM
Sure thing. It's a big one, just so you know...
def data_save(): fileWrite = open('OrdersArchive.txt', 'a') fileWrite.write(str(now)) fileWrite.write(str(cust_name)) fileWrite.write(str(street)) fileWrite.write(str(city)) fileWrite.write(str(state)) fileWrite.write(str(zipcode)) fileWrite.write(str(order_summary)) fileWrite.write(str(order_total)) fileWrite.close() print() return () #above, i am noticing in my txt file output that order_summary and order_total are not printing. here i am just trying to find a way to format the fileout to be somewhat readable and neat. # and thus begins my function to calculate final order total, shipping and state taxes def calculateTotal(products, prices, item_nums, quantity): subtotal = 0 partial_summary = '' order_total = 0 print() print('Items ordered list') print('------------------') width = 6 a = 0 b = 0 t = len(item_list) #here is where i need help formatting the list items to look like " 'product'_________'price'__________'quantity' " while b < t: qty = float(quantity_list[b]) a = int(item_list[b]) price = float(prices[a]) subtotal = (qty * price) order_total = order_total + subtotal print(products[b], '\t\t\t', '$', prices[a], '\t\t', quantity) b = b + 1 if order_total < 40.00: order_total = round(order_total, 2) print("Final order subtotal is", order_total) order_total = order_total + 4.99 print("$4.99 added to all orders under $40") print() order_total = round(order_total, 2) if state == 'CA': order_total = order_total * 1.08 print('CA sales tax added') if state == 'NY': order_total = order_total * 1.07 print('NY sales tax added') order_total = round(order_total, 2) print() print("Total with Shipping: $", order_total) print() return (subtotal, order_total) import datetime now = datetime.datetime.now() products = ['Notebook', 'Atari 2600', 'TrapperKeeper', 'Mod Jeans', 'Insects', 'Harbormaster', 'Lobotomy', 'PunkRock', 'HorseFeathers', 'Super Pants', 'Super Fuzz', 'Salami'] prices = ['1.99', '2.99', '3.99', '4.99', '5.99', '6.99', '7.99', '8.99', '9.99', '10.99', '11.99', '12.99'] item_nums = [1, 2, 3, 4, 5, 6, 7, 8 ,9, 10, 11, 12] item_list = [] quantity_list = [] item_number = 0 quantity = 0 response = '' cust_name = '' street = '' city = '' state = '' zipcode = 0 order_total = 0 order_summary = [] done = 0 order = 0 t = 0 i = len(products) f1 = 0 f2 = 0 print("Jay's House of Rip-Offs\n\n") titles = ('Item Number', 'Item Name', 'Price') data = [titles] + list(zip(item_nums, products, prices)) for i, d in enumerate(data): line = '|'.join(str(x).ljust(16) for x in d) print(line) if i == 0: print('-' * len(line)) while True: order = str.upper(input("\nOrder products [Y / N]?: ")) if order.strip() == 'N': break # no buy break item_nums = input("Enter an item number: ") item_list.append(item_nums) quantity = input("How many? ") quantity_list.append(float(quantity)) if len(item_list) == 0: print("Thank you for browsing.") else: print() cust_name = input("Enter name: ") street = input("Enter street address: ") city = input("Enter city or town name: ") state = str.upper(input("Enter two letter state or province: ")) zipcode = input("Enter zipcode: ") f1, f2 = calculateTotal(products, prices, item_list, quantity_list) data_save() print('Remain Calm and Shop as Usual...')