私は、ユーザーが商品のGTIN-8コードを入力し、必要な金額を入力して領収書を出すコードを作成しています。しかし、製品の量と価格を乗算しようとしているコードの最後の部分に到達すると、 '非整数型のstr'エラーでシーケンスを掛けることはできません。 ここでは、コードの一部です:あなたは、ファイルから値を得たときPython - '' str '型の型の非intでシーケンスを掛けることができません?
ここwhile IfFinished != "Yes":
ProductsWanted=input("Please enter the GTIN-8 Code of the product: ")
AmountOfProducts=input("How many do you want? ")
with open("Productsfile.txt") as f:
for line in f:
if ProductsWanted in line:
Receipt=open("ReceiptFile.txt","a")
Receipt.write("%r, %r, \n" % (line, AmountOfProducts))
Receipt.close()
if ProductsWanted not in ["23456945","12376988","76543111","92674769","43125999"]:
print("Product not found")
else:
print("Product found")
IfFinished=input("Are you done? If so, type 'Yes' ")
if IfFinished == "Yes":
print("Thank you for shopping with us!")
else:
print("Please continue")
Receipt=open("ReceiptFile.txt","r")
print(Receipt.read())
Receipt.close()
with open("ReceiptFile.txt","r") as file:
for line in file:
currentline=line.split(",")
quantity=currentline[3]
ItemPrice=currentline[2]
Totalprice=quantity*ItemPrice
price="0"
Total=price + Totalprice
print(Total)
Pythonからそのままのエラーを投稿してください。 –
あなたは 'quantity'と' ItemPrice'が整数であると仮定しますが、そうではありません。 – Junuxx
'quantity'と' ItemPrice'をチェックしてください。彼らはどのように見えるのですか?どんなタイプですか? – Cleb