The supermarket shopping cart system of Python face test

Source: Internet
Author: User

author = "Superman"


product_list = [
(' Iphone ', 5800),
(' Mac Pro ', 9800),
(' Bike ', +),
(' Watch ', 10600),
(' Coffee '),
(' Alex Python ',
]
shopping_list = []
salary = input ("Input your Salary:")
if Salary.isdigit (): #判断工资是不是数字
salary = Int (salary) #如果是数字就用Int的数据类型
While True: #进入死循环
For Index,item in Enumerate (product_list): #打印商品列表
#print (Product_list.index (item), item)
print (Index,item)
User_choice = input ("Choose what you want to buy?") >>>: ")
if User_choice.isdigit (): #判断工资是数字类型
user_choice = Int (user_choice)
if User_choice < Len (product_list) and User_choice >=0: #判断商品元素数量
P_item = Product_list[user_choice] #通过下标索引把商品取出来
if p_item[1] <= salary: #买的起
shopping_list.append (p_item) #能买得起就把商品添加到列表里
Salary-= p_item[1] #扣钱
print ("Added%s into shopping cart,your current balance is \033[31;1m%s\033[0m"% (p_item,salary))
Else:
print ("\033[41;1m your balance remains [%s], and buy a wool \033[0m"% salary)
Else:
Print ("Product code [%s] is not exist!" % user_choice) #输入的商品序号不存在
elif User_choice = = ' Q ':
print ("--------shopping list------")
For p in shopping_list:
Print (p)
print ("Your Current balance:", salary)
exit ()
Else:
Print ("Invalid option")

The supermarket shopping cart system of Python face test

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.