Shopping cart for Python jobs and shopping cart for python

Source: Internet
Author: User

Shopping cart for Python jobs and shopping cart for python

Implementation:

Can be registered independently,

You can log on to the system for shopping, recharge (not yet implemented), and query the balance.

I spent two days and one night coding. I don't need to talk much about it. I just need to code it directly and comment out what Shenma will do later.

1 #! /Usr/bin/env python 2 #-*-coding: UTF-8-*-3 shopping_list = [4 ['iphone 6 s plus ', 5800], 5 ['luma ', 3800], 6 ['charge', 45], 7 ['data line', 35], 8 ['mi 5 Pro', 2299], 9 ['mx4 ', 1999], 10] 11 salary = 100000 12 total = 0 13 shop_list = [] 14 15 while True: 16 welcome_1 = "Welcome to XXX Shopping Mall" 17 we_1 = welcome_1.center (30, '*') 18 print (we_1) 19 choice_1 = "1. register 2. log on to q. log out of "20 ch_1 = choice_1.center (32, '*') 21 exit_1 =" Thank you! Welcome to "22 ex_1 = exit_1.center (30 ,'*') 23 error_1 = "the user you entered already exists. Enter" 24 e_1 = error_1.center (30, '-') 25 error_2 = "the password cannot be blank, enter "26 e_2 = error_2.center (30, '-') 27 error_3 =" Your password is too short. Please enter "28 e_3 = error_3.center (30, '-') 29 error_4 = "your input is incorrect. Please enter" 30 e_4 = error_4.center (26, '*') 31 error_5 = "your account has been locked, contact the Administrator "32 e_5 = error_5.center (12, '*') 33 print (ch_1) 34 sr_1 = input (" Please input: ") 35 if sr_1 = '1 ': 36 while True: 37 with open('ming.txt ', 'R') as r_1: 38 temp = r_1.readlines () 39 tlist = [] 40 for tline in temp: 41 tline = tline. strip (). split (':') 42 tlist. append (tline [0]) 43 useradd = input ("Please create user:") 44 success_1 = "successfully created user: % s" % (useradd) 45 if useradd in tlist: 46 print (e_1) 47 elif useradd = "exit": 48 break 49 else: 50 passwd = input ("Please create a password (Letters and numbers ):") 51 length = len (passwd) 52 if length = 0: 53 print (e_2) 54 elif length> 7: 55 with open('ming.txt ', 'A') as r_3: 56 w_1 = '% s: 0 \ n' % (useradd, passwd) 57 r_3.write (w_1) 58 s_1 = success_1.center (30 ,'-') 59 print (s_1) 60 break 61 else: 62 print (e_3) 63 64 elif sr_1 = '2': 65 flag = False 66 while True: 67 username = input ("Please enter a user name:") 68 l = open('lock.txt ', 'R') 69 for lline in l. readlines (): 70 lline = lline. strip () 71 if username = lline: 72 print ("account locked") 73 flag = True 74 l. close () 75 break 76 if flag = True: 77 break 78 79 u = open('ming.txt ', 'R') 80 for uline in u. readlines (): 81 user, password, mony = uline. strip (). split (':') 82 83 if username = user: 84 I = 0 85 while I <3: 86 passwd = input ('Please enter a password :') 87 I + = 1 88 if passwd = password: 89 print ('Welcome % s login online shopping platform' % username) 90 flag = True 91 u. close () 92 break 93 else: 94 if I> = 3: 95 with open('lock.txt ', 'A') as l_2: 96 l_2.write (username +' \ n') 97 l. close () 98 exit ("tried too many times, will be locked, please contact the Administrator") 99 print ('wrong password entered, % d chances '% (3-I) 100 break101 else: 102 print ("user input error, please input again") 103 104 105 while True: 106 print ("1. shopping 2. view shopping cart 3. query the balance 4. recharge B. return to login q. exit ") 107 print (" ---------------------------------------------- ") 108 choice_2 = input (" input No.: ") 109 flag_1 = False110 while True: 111 if choice_2 =" 1 ": 112 while True: 113 for index, g in enumerate (shopping_list): 114 print (index, g [0], g [1]) 115 print ("-------------------------") 116 print ("c. view shopping cart B. returns q. exit ") 117 print (" ----------------------- ") 118 choice = input (" type a number to select a product :"). strip () 119 if choice. isdigit (): 120 choice = int (choice) 121 p_price = shopping_list [choice] [1] 122 if p_price <salary: 123 shop_list.append (shopping_list [choice]) 124 total + = p_price125 salary-= p_price126 print ("-------------------------") 127 print ("you purchased % s, balance: % s" % (shopping_list [choice] [0], salary) 128 print ("-----------------------") 129 else: 130 print ("-------------------------") 131 print ("your balance is insufficient") 132 print ("-------------------------") 133 elif choice = "c": 134 while True: 135 print ("---------- shopping cart ----------") 136 for k, v in enumerate (shop_list): 137 print (k, v [0], v [1]) 138 print ("consumed amount: % s" % total) 139 print ("Your available balance: % s" % salary) 140 print ("-------------------------") 141 print ("d. delete item B. return to shopping q. exit settlement ") 142 print (" ------------------------- ") 143 choice_1 = input (" enter a letter to select the function: ") 144 print ("-------------------------") 145 if choice_1 = "d": 146 print ("---------------------------") 147 print ("enter a number to delete the item, enter B to return to the shopping cart ") 148 print ("-------------------------") 149 while True: 150 choice_2 = input ("select:") 151 if choice_2.isdigit (): 152 choice_2 = int (choice_2) 153 d_price = shop_list [choice_2] [1] 154 shop_list.remove (shop_list [choice_2]) 155 total-= d_price156 salary + = d_price157 print ("-------------------------") 158 print ("item % s deleted successfully, available balance: % s" % (shop_list [choice_2] [0], salary) 159 print ("-------------------------") 160 elif choice_2 = "B": 161 break162 elif choice_1 = "B": 163 flag = True164 break165 else: 166 print ("---------- shopping list ----------") 167 for k, v in enumerate (shop_list): 168 print (k, v [0], v [1]) 169 print ("total consumption amount: % s" % total) 170 print ("Your available balance: % s" % salary) 171 print ("-------- welcome next time -------") 172 exit (0) 173 elif choice = "B ": 174 break175 elif choice = "q": 176 print ("---------- shopping list ----------") 177 for k, v in enumerate (shop_list): 178 print (k, v [0], v [1]) 179 print ("total consumption amount: % s" % total) 180 print ("Your available balance: % s" % salary) 181 print ("-------- welcome next time --------") 182 exit (0) 183 else: 184 print ("-------------------------") 185 print ("your input is incorrect, please enter again ") 186 print ("-------------------------") 187 if flag = True: 188 break189 elif choice_2 = "2": 190 print ("---------- shopping cart ----------") 191 for k, v in enumerate (shop_list): 192 print (k, v [0], v [1]) 193 print ("consumed amount: % s" % total) 194 print ("Your available balance: % s" % salary) 195 196 print ("-------------------------") 197 break198 elif choice_2 = "3": 199 with open('ming.txt ', 'R') as m_1: 200 mony_1 = m_1.readlines () 201 for mline in mony_1: 202 (user, password, mony) = mline. strip (). split (':') 203 print (salary) 204 flag_1 = True205 break206 break207 208 elif choice_2 = "4 ": 209 z = 0210 while z <chongzhi = int (input ("input amount:") 212 passwd_1 = input ("Enter Password:") 213 m = open('ming.txt ', 'r + ') 214 m_2 = m. readlines () 215 216 for mline in m_2: 217 (user, password, mony) = mline. strip (). split (':') 218 219 if passwd_1 = password: 220 mony_2 = (chongzhi + int (mony) 221 222 w_2 = '% s: % s \ n' % (username, password, mony_2) 223 m. write (w_2) 224 print ("recharge successful") 225 print (mony) 226 flag = True227 break228 continue229 break230 if flag = True: 231 break1_233 elif choice_2 = "B": 234 flag = True235 break236 237 elif choice_2 = "q": 238 exit (ex_1) 239 else: 240 print (e_4) 241 break242 break243 if flag = True: 244 break245 break246 elif sr_1 = 'q': 247 exit (ex_1) 248 else: 249 print (e_4) 250 print ('') 251 252 253Shopping Cart

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.