Python for mobile phone sales/(), python for mobile phone sales
I just learned the Python function and wrote a job. I will try again later.
The function of adding, deleting, modifying, and querying a mobile phone sales system is simple.
Mobile phone price inventory quantity of mobile phone brands
VivoX9 2798 25
Iphone7 (32G) 4888 31
Iphone7 (128G) 5668 22
Iphone7P (128G) 6616 29
Iphone6 (16G) 3858 14
....
....
...
Functional requirements:
Four options:
1. view all mobile phone brands
VivoX9 2798 25
Iphone7 (32G) 4888 31
Iphone7 (128G) 5668 22
Iphone7P (128G) 6616 29
Iphone6 (16G) 3858 14
.................
..................
Branch options:
1. Select the product serial number to View Details (the product name, price, and inventory are output according to the serial number)
1. Purchase (when the inventory quantity is-1 and the inventory is 0, delete the product)
2. Return
2. Return
2. Change product inventory information
1. Add new products (add new products, including product names, prices, and inventory)
2. modify the original product
Output all product information
1. Modify according to the selected sequence number
2. Return
3. Remove product inventory information
1. view all products and remove them by serial number.
2. Remove all products
3. Return
4. Exit the program
The Code is as follows:
First, define the function of the first vertex.
1 def cha_kan (): 2 if len (all_phone): 3 for x in xrange (0, len (all_phone): 4 phone = all_phone [x] 5 result = phone. values () 6 print x + 1 ,'. ', result [2] 7 print ''' 8 1. select the product serial number to View Details 9 2. return '''10 cao_zuo = input ('Enter the Operation Number: \ n') 11 while cao_zuo! = 1 and cao_zuo! = 2: 12 cao_zuo = input ('sequence number Error !! Please re-enter the Operation Number: n') 13 if cao_zuo = num = input ('Enter the phone number: ') 15 while num <0 or num> len (all_phone ): 16 num = input ('the phone does not exist. Please enter the phone number again: ') 17 if num = one = all_phone [0] 19 print' model :', one ['name'] 20 print 'price:', one ['price'] 21 print 'inventory :', one ['Count'] 22 elif num = one = all_phone [1] 24 print 'model: ', one ['name'] 25 print' price :', one ['price'] 26 print 'inventory: ', one ['Count'] 27 elif num = one = al Rochelle phone [2] 29 print 'model: ', one ['name'] 30 print' price: ', one ['price'] 31 print 'inventory :', one ['Count'] 32 elif num = 4:33 one = all_phone [3] 34 print 'model:', one ['name'] 35 print 'price :', one ['price'] 36 print ':', one ['Count'] 37 elif num = one = all_phone [4] 39 print 'model :', one ['name'] 40 print 'price:', one ['price'] 41 print 'inventory:', one ['Count'] 42 gou_mai () 43 else: 44 pass45 else: 46 print 'so sorry !!! No products now !!'
Cha_kan
Functions of the second and third phases in sequence:
1 def cha_kan (): 2 if len (all_phone): 3 for x in xrange (0, len (all_phone): 4 phone = all_phone [x] 5 result = phone. values () 6 print x + 1 ,'. ', result [2] 7 print ''' 8 1. select the product serial number to View Details 9 2. return '''10 cao_zuo = input ('Enter the Operation Number: \ n') 11 while cao_zuo! = 1 and cao_zuo! = 2: 12 cao_zuo = input ('sequence number Error !! Please re-enter the Operation Number: n') 13 if cao_zuo = num = input ('Enter the phone number: ') 15 while num <0 or num> len (all_phone ): 16 num = input ('the phone does not exist. Please enter the phone number again: ') 17 if num = one = all_phone [0] 19 print' model :', one ['name'] 20 print 'price:', one ['price'] 21 print 'inventory :', one ['Count'] 22 elif num = one = all_phone [1] 24 print 'model: ', one ['name'] 25 print' price :', one ['price'] 26 print 'inventory: ', one ['Count'] 27 elif num = one = al Rochelle phone [2] 29 print 'model: ', one ['name'] 30 print' price: ', one ['price'] 31 print 'inventory :', one ['Count'] 32 elif num = 4:33 one = all_phone [3] 34 print 'model:', one ['name'] 35 print 'price :', one ['price'] 36 print ':', one ['Count'] 37 elif num = one = all_phone [4] 39 print 'model :', one ['name'] 40 print 'price:', one ['price'] 41 print 'inventory:', one ['Count'] 42 gou_mai () 43 else: 44 pass45 else: 46 print 'so sorry !!! No products now !!'
Cha_kan
1 def yi_chu (): 2 print ''' 3 1. view all products and remove 4 2 according to the serial number. remove all products. return '''6 xh = input ('Enter the serial number: ') 7 while xh! = 1 and xh! = 2 and xh! = 3: 8 xh = input ('sequence number error :!!! Re-enter the serial number: ') 9 if xh = for x in xrange (0, len (all_phone): 11 phone = all_phone [x] 12 result = phone. values () 13 print x + 1 ,'. ', result [2] 14 gen_ju = input (' Delete according to the serial number. Enter the serial number: ') 15 while gen_ju <0 or gen_ju> len (all_phone ): 16 gen_ju = input ('sequence number error :!!! Re-enter serial number: ') 17 if gen_ju = all_phone.pop (gen_ju-1) 19 print' deleted successfully !! '20 elif gen_ju = all_phone.pop (gen_ju-1) 22 print' deleted successfully !! '23 elif gen_ju = all_phone.pop (gen_ju-1) 25 print' deleted successfully !! '26 elif gen_ju = all_phone.pop (gen_ju-1) 28 print' deleted successfully !! '29 elif gen_ju = all_phone.pop (gen_ju-1) 31 print' deleted successfully !! '32 elif xh = while len (all_phone): 34 del all_phone [0] 35 print 'deleted successfully !! '36 else: 37 pass
Yi_chu
I wrote an additional function to view the internal purchases.
1 def gou_mai (): 2 print ''' 3 1-purchase 4 2-return '''5 xz = input ('Enter the Operation Number: ') 6 while xz! = 1 and xz! = 2: 7 xz = input ('input Error !! Enter the operation number again: ') 8 if xz = 1: 9 one = all_phone [0] 10 value = int (one ['Count']) -111 one ['Count'] = str (value) 12 print ': purchase successful !!! '13 else: 14 pass
Gou_mai
Then begin to write the complete step of the entire subject.
1 while 1: 2 print ''' 3 1. view all mobile phone brands 4. change product inventory information 5. remove product inventory information 4. exit the program ''' 7 shu_ru = input ('enter the operation serial number:') 8 while shu_ru! = 1 and shu_ru! = 2 and shu_ru! = 3 and shu_ru! = 4: 9 shu_ru = input ('input Error !!! Please re-enter operation number: ') 10 if shu_ru = cha_kan () 12 elif shu_ru = geng_gai () 14 elif shu_ru = yi_chu () 16 else: 17 break
Subject
There are also a lot of errors, which can be basically run, and later I learned other methods to come in and change them.