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
#1
I am working on my class project and am having some difficulty getting my print statement to format "neatly". Teacher wants it to look like this when it prints-- ex.'TrapperKeeper________$3.99________13' So, 'product', 'price' and 'quantity'

I am also having similar issues formatting the text I am saving in the .txt file at the end (want to have each field separated by a ' : ')

Here is the code for the first issue:

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)

        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
And this is the save to file script, which is ugly, but functional. I just need it to format more neatly as well. I have always had trouble with formatting things to actually look readable and nice, which may be my project over the holidays.

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))
        print()
        return ()
        data_save()
Reply


Messages In This Thread
Help Formatting Print Statement (input from 3 lists) X 2 - by Hebruiser - Nov-29-2017, 11:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Post IF Statement Input OrphanedSoul 2 2,315 Jun-04-2021, 05:03 PM
Last Post: deanhystad
  Problem with print formatting using definitions Tberr86 2 1,998 Mar-20-2021, 06:23 PM
Last Post: DPaul
Bug How to print only vowels from an input? PP9044 8 7,517 Feb-26-2021, 04:02 PM
Last Post: Serafim
  Print user input into triangle djtjhokie 1 2,370 Nov-07-2020, 07:01 PM
Last Post: buran
  How to print the docstring(documentation string) of the input function ? Kishore_Bill 1 3,541 Feb-27-2020, 09:22 AM
Last Post: buran
  Print the longest str from user input edwdas 5 4,139 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,384 Feb-10-2019, 12:21 PM
Last Post: DeaD_EyE
  if/else statement only outputs else statement regardless of input KameronG 2 2,601 Feb-08-2019, 08:04 AM
Last Post: KameronG
  How to force print statement to print on one line wlsa 4 3,535 Oct-28-2018, 09:39 PM
Last Post: wavic
  Print The Length Of The Longest Run in a User Input List Ashman111 3 3,190 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