python object-oriented application case: Braised chicken wings

requirement analysis

The process of burning chicken wings is divided into: barbecue and seasoning

In order to realize it in an object-oriented way, we must define the chicken wing class, which has the following attributes: barbecue time, maturity, seasoning. And the following methods: barbecue, adding seasoning

Correlation between barbecue time and ripening time:

  • 0-3 minutes: raw
  • 3-5 minutes: half cooked
  • 5-8 minutes: ripe
  • More than 8 minutes: burnt
Braised chicken wings

The code implementation is as follows:

class Wing():
    """Braised chicken wings"""

    def __init__(self):
        print('----Braised chicken wings, my favorite food-----')
        self.cookedLevel = 0  # Time to burn chicken wings
        self.cookedString = 'Raw'  # Degree of maturity
        self.condiments = []  # To flavor
        print('The chicken wings I just bought are raw and have no seasoning')

    def cook(self, time):
        self.cookedLevel += time
        if self.cookedLevel > 8:
            self.cookedString = 'Scorched'
        elif self.cookedLevel > 5:
            self.cookedString = 'It's done'
        elif self.cookedLevel > 3:
            self.cookedString = 'halfcooked'
            self.cookedString = 'Raw'

    def addCondiments(self, condiments):
        print('---Add seasoning---')

    def __str__(self):
        print('----Burned%s Minute---' % self.cookedLevel)
        msg = 'Maturity of wings:' + self.cookedString
        if len(self.condiments) > 0:
            msg = msg + "\n The seasonings are:"
            for temp in self.condiments:
                msg = msg + temp + ', '
            msg = msg.rstrip(', ')
        return msg

wing = Wing()

print('----Start to cook chicken wings----')

wing.addCondiments('soy sauce')





----Braised chicken wings, my favorite food-----
The chicken wings I just bought are raw and have no seasoning
 ----Start to cook chicken wings----
----Burned for 4 minutes---
Maturity of chicken wings: half cooked
 ---Add seasoning---
----Burned for seven minutes---
Cooked chicken wings: cooked
 Seasoning: soy sauce
 ---Add seasoning---
----Burned for eight minutes---
Cooked chicken wings: cooked
 Seasoning: soy sauce, sesame
 ----Burned for 10 minutes---
Cooked chicken wings: burnt
 Seasoning: soy sauce, sesame

Posted on Thu, 30 Apr 2020 04:41:15 -0700 by MattMan