Printing Data in proper aligned format in python

pid=[1,2,3,4,5]
name=["Pen","Pencil","Eraser","Sharpner","Compass"]
qty=[200,400,100,100,20]
rate=[20,5,2,4.5,100]
amt=[]
print("**************************************")
print("ID  Product Name   Qty. Rate   Amount")
print("**************************************")
for i in range(0,len(pid)):
    print("%3d "%pid[i],end="")
    print("%-14s "%name[i],end="")
    print("%4d "%qty[i],end="")
    print("%6.2f "%rate[i],end="")
    amt.append(qty[i]*rate[i])
    print("%7.2f"%amt[i])
print("**************************************")
print("%31s"%"Total Amount: ",end="")
print("%7.2f"%sum(amt))
print("**************************************")





No comments

Post your comments

Powered by Blogger.