Calculate the total amount of money from the text

A.txt file contents: the contents of each row are trade name, price, number, number calculated the total cost of this shopping money

apple 10 3
tesla 100000 1
mac 3000 2
lenovo 30000 3
chicken 10 3

```/python
sum=0
with open('a.txt', 'rt', encoding='utf8') as f:
# print(f.read())
# print(f.readlines())
for i in f.readlines():
i=i.strip().split(" ")
# print(i)
# a=i[1]
# print(a)
# print(type(a))
# a=int(i[1])
sum+=int(i[1])*int(i[2])
print(sum)
196060

Guess you like

Origin www.cnblogs.com/jinhongquan/p/11317172.html