2017-04-06 11 views
0

私は、ユーザーが商品の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) 
+0

Pythonからそのままのエラーを投稿してください。 –

+0

あなたは 'quantity'と' ItemPrice'が整数であると仮定しますが、そうではありません。 – Junuxx

+0

'quantity'と' ItemPrice'をチェックしてください。彼らはどのように見えるのですか?どんなタイプですか? – Cleb

答えて

1

、彼らは文字列型である:

quantity=currentline[3] 
ItemPrice=currentline[2] 

あなたが掛ける前にintにそれらを変換する必要があり、たとえば、

quantity=int(currentline[3]) 
+0

[回答]に記載されているように、不明瞭、過度に広範な、誤植、意見に基づく、再現性のない、または重複する質問には回答しないでください。 Write-my-codeリクエストと手間のかからない質問は[so]の話題にはならず、プロのコーディング/個人指導サービスに適しています。良い質問は[質問する]、[mcve]を含める、研究努力をして、将来の訪問者に役立つ可能性を秘めています。不適切な質問に答えることで、ナビゲートするのをより困難にし、さらにそのような質問を奨励することで、時間と専門知識をボランティアする他のユーザーを追い払うことができます。 – TigerhawkT3

関連する問題