Skip to content
Advertisement

Print output for data list python

I am trying to print an output but I just can’t figure out method.

keepAsking = True
author = ""
booktitle = ""
purchaseprice = float()
sellprice = float()
stockcount = int()
margin = float()
bookList = []
priceList = []

while keepAsking == True :
    print("Enter Book Data: -")

    author = input("Author: ")
    if author == "" :
        print("Blank Entry")
    else :
        booktitle = input("Title: ")
        if booktitle == "" :
            print("Blank Entry")
        else :
            purchaseprice = input("Purchase Price: ")
            if purchaseprice == "" :
                print("Incorrect Value")
            else :
                sellprice = input("Sell Price: ")
                if sellprice == "" :
                    print("Incorrect Value")
                else :
                    bookList.append(author)
                    bookList.append(booktitle)
                    if purchaseprice > sellprice :
                        bookList.remove(author)
                        bookList.remove(booktitle)
                    else :
                        priceList.append(purchaseprice)
                        priceList.append(sellprice)
                        stockcount = input("In Stock: ")
                        if stockcount == "" :
                            print("Incorrect Value")
                        else :
                            priceList.append(stockcount)

                    
    margin = ((float(sellprice)-float(purchaseprice))/float(purchaseprice))*100
    marginround = round(margin,2)
    priceList.append(marginround)
                    
    checkContinue = True
    while checkContinue == True :
        continues = input("Continue? [y/n]")
        continuesLower = continues.lower()

        if continues == "y" :
            checkContinue = False

        if continues == "n" :
            checkContinue = False
            keepAsking = False

and I am trying to get an output like this: output

I don’t really understand array and I have tried a few methods but failed to output it as the image shows. If possible, I would need some explanation too because I want to learn rather than get the answer straight out. So, if you have a solution, I might ask for more information on it too. (you don’t have to explain it if you are not comfortable, but I just wish to learn more)

Thank you for attempting to help me. I am sorry if this is just a simple task but I am less than a beginner and trying to improve myself.

I am currently not outputting anything enter image description here

my print code is

for a in bookList :
            counter = 0
            while counter == len(bookList) :
                print(bookList[0] + bookList[1])
                print("Purchase Price: " + priceList[0] + "Sell Price: " + priceList[1] + "In Stock: " + priceList [2] + "Margin: " + priceList [3])

Advertisement

Answer

  1. If you want to print multiple Book names and prices, etc you should put each one of them into a separate list in this case. (with append)
  2. If you want to print them out you can do like this:
for i in range(0, len(booklist)):
   print(author[i] + '  Purchase:' + purchase[i] + '   Sell:' + sell[0]))

… etc to the right format in wich purchase and sell are all lists. Don’t forget to add spaces. To check if the person actually input numbers you can use the method .isdigit()

if purchaseprice.isdigit() != true :
   print("Incorrect Value, input numbers")
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement