Python----Job 0329

Source: Internet
Author: User

Shopping Cart Program (teacher method)

Product_list = [[' Iphone7 ', 5800], #列表方式 [' Coffee ', 30], [' Lump soup ', 10],                 [' Python book ', [], [' Bike ', 199], [' ViVo X9 ', 2499],]shopping_cart = [] #shopping_cart Cart salary = Int (input ("Input your Salary:")) #请输入你的资产while True:in Dex = 0 for product in Product_list:print (index,product) Index + = 1 choice = input ("&GT;&GT;:"). Strip () if Choice.isdigit (): #判断是否为数字 choice = Int (choice) if choice >= 0 and Choice < Len (Product_lis                T): #商品存在 product = Product_list[choice] #取到商品 if product[1] <= salary: #判断是否买得起                #买得起 shopping_cart.append (product) #加入购物车 salary-= product[1] #扣钱 Print ("Added product" + product[0] + "into shopping cart,your current balance") else:print ("Buy not UP, poor force! The product price is "+ STR (producT[1]) + "You are poor" + str (product[1]-Salary) + "¥") else:print ("The product does not exist!")            ") elif choice = =" Q ": Print ("------List of Purchased items------") for I in Shopping_cart:print (i) Print ("Your balance is:", salary) print ("-----End-----") Break Else:print ("No this option!")

  

Python----Job 0329

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.