Wrox Programmer Forums
BOOK: Beginning Python: Using Python 2.6 and Python 3.1
This is the forum to discuss the Wrox book Beginning Python: Using Python 2.6 and Python 3.1 by James Payne; ISBN: 978-0-470-41463-7
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Python: Using Python 2.6 and Python 3.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old March 15th, 2012, 03:41 PM
Registered User
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


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
            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)
        print("I don't think I can make this kind of omelet: %s" % omelet_type)
Can somebody help, thanks
Old March 22nd, 2012, 06:00 PM
Registered User
Join Date: Mar 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Cool chapter5 function

You need one more function make_food(ingredients_needed, food_name)
# than the following code
>>>fridge = {'apples':10, 'oranges':3, 'milk':2}
>>>omelet_type = make_omelet_q3(fridge, {'eggs':2, 'jack_cheese':2, 'milk':1,'mushrooms':2})

And you should see...
omelet_type is a dictionary with ingredients
Adding 2 of jack_cheese to make a omelet
Adding 2 of mushrooms to make a omelet
Adding 2 of eggs to make a omelet
Adding 1 of milk to make a omelet

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems on tracing output of Multitouch code in Device Central CS5 htyap2 BOOK: Beginning Flash, Flex, and AIR Development for Mobile Devices 0 February 9th, 2012 04:07 AM
Code to output the LINQ query that groups doesn't work on my system mangel BOOK: Professional Visual Basic 2010 and .NET 4 2 April 4th, 2011 04:39 PM
Ex10_01 Identical code, different output tonyjeffs BOOK: Ivor Horton's Beginning Visual C++ 2005 4 December 7th, 2007 05:50 AM
Can't Run the Code geotechman BOOK: ASP.NET Website Programming Problem-Design-Solution 1 October 12th, 2004 09:08 PM
Better way to run this code harpua Classic ASP Databases 6 February 27th, 2004 03:41 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.