How do I make my the items in my basket add together, without the code breaking?
This is my code so far:
import time stock=['cheese', 'crackers', 'kitchens', 'couches', 'computers', 'chickens', 'cats', 'chocolate', 'keys', 'violins']prices = ['1.50', '2.00', '500.00', '100.00', '350.00', '75.00', '80.00', '1.00', '5.00', '250.00']basket= []bill = []choseagain = "y"print("Welcome to our shop.")time.sleep(1)x=input ("What is your name? ")print("Hello " + x, ". Welcome to our shop.")time.sleep(1)print("Our shop sells", stock)while choseagain == 'y': search=input("What would you like to buy? ")if search in stock: time.sleep(1) itemNo=stock.index(search) basket.append(search) stock.remove(search) bill.append(prices[itemNo]) print("You are in luck, we sell",search,"for £",prices[itemNo], "each") print("Your basket contains:", basket) choseagain = input("Do you want to buy anything? y or n?")else: time.sleep(1) print("Unfortunately we just ran out",search,"but we do sell", stock) time.sleep(1) print("Your basket contains:", basket) choseagain = input("Do you want to buy anything? y or n?")while choseagain == 'n': finalbill=sum(bill) print('Your final bill is £{:.2f}',format(finalbill)) print("Please pay due amount") print("Have a good day")the main problem is finalbill=sum(bill) as an error saying Python error unsupported operand type(s) for +: 'int' and 'str'? I have tried to put: finalbill=int(sum(bill))and finalbill=str(sum(bill))
أكثر...
This is my code so far:
import time stock=['cheese', 'crackers', 'kitchens', 'couches', 'computers', 'chickens', 'cats', 'chocolate', 'keys', 'violins']prices = ['1.50', '2.00', '500.00', '100.00', '350.00', '75.00', '80.00', '1.00', '5.00', '250.00']basket= []bill = []choseagain = "y"print("Welcome to our shop.")time.sleep(1)x=input ("What is your name? ")print("Hello " + x, ". Welcome to our shop.")time.sleep(1)print("Our shop sells", stock)while choseagain == 'y': search=input("What would you like to buy? ")if search in stock: time.sleep(1) itemNo=stock.index(search) basket.append(search) stock.remove(search) bill.append(prices[itemNo]) print("You are in luck, we sell",search,"for £",prices[itemNo], "each") print("Your basket contains:", basket) choseagain = input("Do you want to buy anything? y or n?")else: time.sleep(1) print("Unfortunately we just ran out",search,"but we do sell", stock) time.sleep(1) print("Your basket contains:", basket) choseagain = input("Do you want to buy anything? y or n?")while choseagain == 'n': finalbill=sum(bill) print('Your final bill is £{:.2f}',format(finalbill)) print("Please pay due amount") print("Have a good day")the main problem is finalbill=sum(bill) as an error saying Python error unsupported operand type(s) for +: 'int' and 'str'? I have tried to put: finalbill=int(sum(bill))and finalbill=str(sum(bill))
أكثر...