Mar-23-2019, 08:30 PM
(This post was last modified: Mar-23-2019, 08:30 PM by SilverLeaf90.)
Can anyone lend me some help on this issue. I need to print from a list that contains some data. But 2 of the elements in that list are different than plain strings. 1 is a date and the other is a price.
Example code:
This is a constant named PURCHASERS that contains the data. I need to print this out and convert the 3rd & 4th elements to English date format and American currency.
This is what I have written so far, but it isn't working at all. I figured I could call the 3rd element to be turned into a string, and then turned into the American format.
:
Example code:
This is a constant named PURCHASERS that contains the data. I need to print this out and convert the 3rd & 4th elements to English date format and American currency.
PURCHASERS = [["GH456", "Alexander", "Apples", date(2005,3,6), 3.89 ] ["GH289", "Billy", "Pears", date(2005,7,11), 2.99], ["GH089", "Todd", "Cereal", date(2005,8,10), 4.15], ["GH223", "Fred", "Bread", date(2005,1,5), 2.89]]
This is what I have written so far, but it isn't working at all. I figured I could call the 3rd element to be turned into a string, and then turned into the American format.
from datetime import date import locale as lc PURCHASERS = [["GH456", "Alexander", "Apples", date(2005,3,6), 3.89 ] ["GH289", "Billy", "Pears", date(2005,7,11), 2.99], ["GH089", "Todd", "Cereal", date(2005,8,10), 4.15], ["GH223", "Fred", "Bread", date(2005,1,5), 2.89]] def main(): print("NUMBER\t\tNAME\tITEM-TYPE\t\tDATE\t\tPRICE ") lc.setlocale(lc.LC_ALL, 'us') date_purchased = date.PURCHASERS(3) print(PURCHASERS.date_purchased.strftime("%d %b %Y")) if __name__ == "__main__": main()I need my output to look like a nice table too

Output:NUMBER NAME ITEM TYPE DATE PRICE
GH456 Alexander Apples 3/6/2005 $3.89