I am trying to read this text file and display its data. I should report product name, its value & most valuable product. I added at the end what I have tried doing so far:
Here is how the text file looks like:
item name 1 ex: hats
quantity of item 1 ex: 12
unit price of item 1 ex: 5.9
item name 2 ex: jacket
quantity of item 2 ex: 13
unit price of item 2 ex: 29.9
Expected output
12 hats at 5.9 the unit. total value: 70.8
13 jackets at 29.9 the unit. total value: 390
total inventory value: 460.8
most valuable inventory: jacket: 390
what I've tried doing so far:
filename = "store.txt"
with open(filename) as f:
content = f.read().splitlines()
content_list = [content[i * 3:(i + 1) * 3] for i in range((len(content) + 3 - 1) // 3)]
total_value = 0
for items in content_list:
value = float(items[2])*(float(items[1]))
print(items[1],'', items[0], '@ $', items[2], '. Value: $', value)
total_value += value
#max_value = max(value)
print('')
print('total value: '+ str(total_value))
#print('Highest value item: ' + str(max_value))