preface

This evening just came off work, aunt brought my favorite durian over, said not to eat bad.

I saw her intention at a glance, ha ha ha I this aunt is also grew up together, her heart I know! You must want something from me! Then just ask him if he can help you. Just say it!

Aunt: recently, the fruit store is not to count the number of fruit every day. It’s too much work, and it takes time. You know I hate these jobs, and it’s not worth it to hire one person, so if you’re a programmer, write one for me.

I: see in durian of share top, I eat a bit deficient help you write 1, however I write of very humble of ha, with somebody else that kind of already developed of affirmation have no ratio of, however you also use oneself, should influence not big!

Aunt: Ok, remember to give it to me tomorrow

Me: This is the same as the product manager, but also work overtime to make it for her!

The body of the

PS: If you need Python learning materials, please click on the link below to obtain them

Free Python learning materials and group communication solutions click to join

Class Fruit: def __init__(self, fname, price, count, remark): Self.fname = fname self.price = price self.count = count self.remark = remark def show_info(self): Print ("%s\t\t%d\t\t%d\t\t%s"%(self.fname, self.price, self.count, self.remark)) class Menu: A menu class def __init__(self): Define a structure, F1 = Fruit(" Fruit ", 6, 10, "Fruit is delicious ") f2 = Fruit(" kiwifruit ", 10, 20," kiwifruit is very sour ") self.fruit_list = [f1, Def show_main_menu(self): Print (" = = = = = = = = = = = = = = = = = = = = = = welcome to use fruit inventory system = = = = = = = = = = = = = = = = = = = = = = = = = = ") print (" 1. ") print("2. Add new fruit ") print("3. ") print("4. Fruit down ") print("5. ") print("="*65) return eval(input(" please select: ")) def fruit(self): Fname = input(" please enter the fruit name: ") f = self.get_fruit(fname) # Price = eval(input(" input ")) count = eval(input(" input ") F = Fruit(fname, price, count, remark) self.fruit_list.append(f) else: Count = eval(input(" input ")) f.count = f.count + count print(" added successfully!") Def get_fruit(self,fname): # fruit_list: if f.fruit.__eq__ (fname): Return f return None def show_fruit(self): Fname = input(" please input fruit name: ") f = self.get_fruit(fname) print("-"*65) print(" name \t\t unit price \t\t stock \t\t note ") if f is None: print(" ) else: f.show_info() print("-"*65) def del_fruit(self): Fname = input(" fname = input ") f = self.get_fruit(fname) if f is not None: SLT = input(" (Y/N)") if "Y".__eq__(slt.upper()): self.fruit_list.remove(f) Return print(" No information found for fruit to be removed!" ) def show_fruit_list(self): Print ("-"*65) print(" name \t\t unit price \t\t stock \t\t note ") if self.fruit_list is None or len(self.fruit_list)==0: Print (" Sorry, stock is empty!" ) else: for f in self.fruit_list: f.sho_info () print("-"*65) def my_exit(self): (Y/N)") flag= not "Y".__eq__(slt.upper()) # Return flag m = Menu() flag=True while flag: # SLT = m.how_main_menu () if SLT == 1: m.show_fruit_list() elif slt == 2: m.add_fruit() elif slt == 3: m.show_fruit() elif slt == 4: M.del_fruit () elif SLT == 5: flag = m.my_exit() print(" )Copy the code

Above is this “fruit shop small system” all code. The effect is as follows:

! [](https://p3-tt-ipv6.byteimg.com/large/pgc-image/7b9555df8c6a4beaa3f4dbc5edd8e2fe)

Want to perfect this function, we directly apply the code line!