我正在写一段代码来完成滚动。我努力在文本文件中获取价格并将其乘以用户输入的数量。我不知道如何解决。努力从文本文件中乘以一个数字(Python)
这就是我迄今为止所做的;
的代码部分也是如此,下面
def receipt():
food = input("Enter the product code for the item you want.")
fi = open("data.txt","r")
info = fi.readlines()
fi.close()
item = False
for li in info:
if(li.split(":")[0].lower() == food):
print(li.split(":")[1])
item = True
quantity = input("How many do you want?")
print("£" + quantity)
receipt()
的文本文件:
12345670:Burgers, £1:1.30
19203123:Cheese, £2.50:2.50
98981236:Crisps, 0.55p:0.55
56756777:Alphabetti Spaghetti, £1.45:1.45
90673412:Sausages, £2.30:2.30
84734952:Lemonade, 0.99p:0.99
18979832:Ice Cream, £1.50:1.50
45353456:6 Pack of Beer, £5:5.00
98374500:Gum, 0.35p:0.35
85739011:Apples, 0.70p:0.70
我想我必须使用.append或名单,但我不知道他们是如何工作的我还没有学到他们。
有什么麻烦?什么是错误?预期产出是多少? – timgeb
为什么每一行的价格是两倍? – timgeb
你的代码试图进行乘法运算的地方在哪里?如果你不发布代码,我们应该如何向你展示你做错了什么? – Barmar