Python Automation development-ex03 (shopping cart implementation)

Source: Internet
Author: User

#!/usr/bin/Env python#-*-coding:utf-8-*-# Author:DaShuang.Gu" "Requirements:Buyers1. Product information exists in the file2. Purchased goods, Balance records. The first time you start a program, you need to record your salary, and the second time you start the program, the last balance is displayed3. Allow users to purchase items based on their product number4after the user selects the product, the detection is enough, enough on the direct debit, enough to remind5. Can exit at any time, when exiting, print move purchase goods and balances merchant entrance: Can add goods, modify commodity price, run program output first level menu" "Product_list = [    ('Iphone',5800),    ('Mac Pro',9800),    ('Bike', -),    ('Watch',10600),    ('Coffee', to),    ('Alex Python', -),]shopping_list=[]user_salary= Input ("Please enter your salary:")ifuser_salary.isdigit (): User_salary=int(user_salary) whileTrue: #打印出商品信息 print ('Product List'. Center ( -,'*'))     forIndex,iteminchEnumerate (product_list): Print (index,item) # BreakShopping_number= Input ("output The item number you want to buy:")    ifshopping_number.isdigit (): Shopping_number=int(Shopping_number)ifShopping_number < Len (product_list) and Shopping_number >=0: P_item=Product_list[shopping_number]ifUser_salary >= p_item[1]: Shopping_list.append (p_item) user_salary-= p_item[1] Print ("product%s added to cart with balance%s"%(P_item, user_salary))Else: Print ('Insufficient balance%s'%user_salary)Else: Print ('the product number entered does not exist') elif Shopping_number=='Q': Print ('Shopping list'. Center ( -,'*'))         forIinchshopping_list:print (i) Print ("also multiply the balance%s"%user_salary) exit ()

Python Automation development-ex03 (shopping cart implementation)

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.