View Single Post
  #1 (permalink)  
Old March 15th, 2012, 03:41 PM
Eduardo Tarik Eduardo Tarik is offline
Registered User
Points: 24, Level: 1
Points: 24, Level: 1 Points: 24, Level: 1 Points: 24, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2011
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Question How to get the output or run this code?

Hello, I don't know what to do with this code of chapter 5, third exercise.
I did check the solutions, but it doesn't tell how to run it

Here is the code

Code:

def make_omelet_q3(fridge, omelet_type = 'mozzarella'):

    def get_omelet_ingredients(omelet_name):
        ingredients = {'eggs':2, 'milk':1}
        if omelet_name == 'cheese':
            ingredients['cheddar'] = 2
        elif omelet_name == 'western':
            ingredients['jack_cheese'] = 2
            ingredients['ham']         = 1
            ingredients['pepper']      = 1
            ingredients['onion']       = 1
        elif omelet_name == 'greek':
            ingredients['feta_cheese'] = 2
            ingredients['spinach']     = 2
        elif omelet_name == 'mozzarella':
            ingredients['mozzarella cheese'] = 2
            ingredients['roast red pepper']  = 2
            ingredients['mushrooms']         = 2
        else:
            print("That's not on the menu, sorry!")
            return none
        return ingredients

    def remove_from_fridge(needed):
        recipe_ingredients = {}
        for ingredient in needed.keys():
            if needed[ingredient] > fridge[ingredient]:
                raise LookupError('not enough %s to continue' % ingredient)
        for ingredient in needed.keys():
            fridge [indgredient] = fridge[ingredient] - needed[ingredient]
            recipe_ingredients[ingredient] = needed[ingredient]
        return recipe_ingredients
    if type(fridge) != type({}):
        raise TypeError("The fridge isn't a dictionary!")
    if type(omelet_type) == type({}):
        print('omelet_type is a dictionary with ingredients')
        return make_food(omelet_type, "omelet")
    elif type(omelet_type) == type(""):
        needed_ingredients = get_omelet_ingredients(omelet_type)
        omelet_ingredients = remove_from_fridge(needed_ingredients)
        return make_food(omelet_ingredients, omelet_type)
    else:
        print("I don't think I can make this kind of omelet: %s" % omelet_type)
Can somebody help, thanks
Reply With Quote