Simple shopping cart written in python

#coding utf-8
#1. Design a shopping cart program that prompts the user to enter the salary. After the salary is input, the product list is opened, and the user is prompted to select the purchased product
. #2. After selecting the product, if the balance is sufficient, the purchase is successful and the product is printed. List, otherwise the purchase fails and the balance is displayed

salary=int(input("Please input your salary:"))
goodsList=[['Sony TV',3888],['Apple Computer',8999],['Wok',199],["Iphone6 ",3888],["Teacup",77]]
changGoodList=[]
i=1
print("The goods you entered are as follows:")
for good in goodsList:
print("%d---%s---- %d"%(i,good[0],good[1]))
i+=1

flag=True

while flag:
changGoodNumber = int(input("Please select the serial number of the product you want to buy:"))
if changGoodNumber<=len(goodsList):
if int(salary)-goodsList[changGoodNumber-1][1]>=0:
print("Successful purchase, the goods you purchased are %s"%(goodsList[changGoodNumber-1][0]))
changGoodList.append(goodsList[changGoodNumber - 1][0])
salary=salary-int(goodsList [changGoodNumber - 1][0]) -1][1])
print("Your salary balance is %d yuan"%salary)
else:
print("Insufficient balance, unable to purchase, the program exits")
flag=False
else:
print("There is no such product, please reselect")

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325673598&siteId=291194637