Pyhton shopping program, pyhton shopping

Source: Internet
Author: User
Tags dell xps

Pyhton shopping program, pyhton shopping

Requirements:

Readme:

Run the program, enter the salary, and select the purchased item based on the serial number of the product list. You can choose to purchase multiple times or not to purchase

 

Flowchart:

 

 

Code:

1 # simple Shopping mini app 2 3 product_list = [4 ['surface pro 4', 7800], 5 ['Dell xps 15', 12000], 6 ['macbook ', 12000], 7 ['xiaomi 6', 2499], 8 ['iphone7', 4600], 9 ['Nut Pro ', 1499] 10] 11 shopping_list = [] 12 13 14 # judge whether the input salary format is correct 15 while True: 16 salary = input ('\ n enter your salary :') 17 if not salary. isdigit (): # The salary is not a number. The end cycle is 18 print ('\ n input format is incorrect! Please input again... ') 19 continue20 break21 22 23 balance = salary = int (salary) 24 25 print (' \ n ----------- welcome to purchase ------------ \ n ') 26 27 # generate product list with serial number 28 for index, item in enumerate (product_list): 29 print (index, item) 30 31 32 # determine whether the input Serial number meets the requirements 33 while True: 34 35 while True: 36 I = input ('\ n enter the serial number of the product you want to purchase, or enter q to cancel the purchase: ') 37 if I = 'q': # Enter q to exit the purchase page 38 while True: 39 a = input (' \ n continue to purchase? (Y/N): ') 40 if! = 'N' and! = 'N' and! = 'Y' and! = 'Y': 41 print ('\ n input format is incorrect. Please try again... ') 42 continue43 elif a = 'y' or a = 'y': # continue to buy 44 break45 else: #46 if balance = salary: # Didn't buy anything 47 print ('\ n transaction ended, purchase failed... ') 48 exit () 49 else: # settlement 50 print (' \ n you have successfully purchased the following items: \ n') 51 for item in shopping_list: 52 print (item) 53 print ('\ n total consumption amount % d yuan, balance % d yuan' % (salary-balance, balance) 54 exit () 55 continue56 57 if not I. isdigit (): # The serial number is not a number. The ending loop 58 print ('\ n input format is incorrect! Please input again... ') 59 continue60 61 I = int (I) 62 63 if I <0 or I> = len (product_list): # the sequence number range is incorrect, end loop 64 print ('\ n This item does not exist, please enter again... ') 65 continue66 break67 68 product = product_list [I] 69 price = int (product [1]) 70 71 # determine whether the balance is sufficient and deduct the fee if it is sufficient, not enough reminder 72 if price <= balance: 73 balance-= price74 shopping_list.append (product_list [I]) 75 print ('\ n you have successfully purchased % s, the current balance is % d yuan '% (product, balance) 76 else: 77 print (' \ n purchase failed, your balance is insufficient... ') 78 79 while True: 80 a = input ('\ n continue to purchase? (Y/N): ') 81 if! = 'N' and! = 'N' and! = 'Y' and! = 'Y': 82 print ('\ n input format is incorrect. Please try again... ') 83 continue84 break85 86 if a = 'y' or a = 'y': 87 continue88 else: 89 break90 91 if balance = salary: 92 print ('\ n transaction ended, purchase failed... ') 93 exit () 94 else: 95 print (' \ n you have successfully purchased the following items: \ n') 96 for item in shopping_list: 97 print (item) 98 print ('\ n total consumption amount % d yuan, balance % d yuan' % (salary-balance, balance) 99 exit ()

 

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.