Python Forum
Help Formatting Print Statement (input from 3 lists) X 2
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help Formatting Print Statement (input from 3 lists) X 2
#5
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...')
Reply


Messages In This Thread
RE: Help Formatting Print Statement (input from 3 lists) X 2 - by Hebruiser - Dec-01-2017, 01:51 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Post IF Statement Input OrphanedSoul 2 2,400 Jun-04-2021, 05:03 PM
Last Post: deanhystad
  Problem with print formatting using definitions Tberr86 2 2,052 Mar-20-2021, 06:23 PM
Last Post: DPaul
Bug How to print only vowels from an input? PP9044 8 7,711 Feb-26-2021, 04:02 PM
Last Post: Serafim
  Print user input into triangle djtjhokie 1 2,449 Nov-07-2020, 07:01 PM
Last Post: buran
  How to print the docstring(documentation string) of the input function ? Kishore_Bill 1 3,601 Feb-27-2020, 09:22 AM
Last Post: buran
  Print the longest str from user input edwdas 5 4,241 Nov-04-2019, 02:02 PM
Last Post: perfringo
  How to print a statement if a user's calculated number is between two floats Bruizeh 2 2,449 Feb-10-2019, 12:21 PM
Last Post: DeaD_EyE
  if/else statement only outputs else statement regardless of input KameronG 2 2,679 Feb-08-2019, 08:04 AM
Last Post: KameronG
  How to force print statement to print on one line wlsa 4 3,650 Oct-28-2018, 09:39 PM
Last Post: wavic
  Print The Length Of The Longest Run in a User Input List Ashman111 3 3,255 Oct-26-2018, 06:56 PM
Last Post: gruntfutuk

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020