Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Open Source > BOOK: Beginning Python: Using Python 2.6 and Python 3.1
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 15th, 2012, 03:41 PM
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
  #2 (permalink)  
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
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 03: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 04: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 02:41 PM



All times are GMT -4. The time now is 02:08 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.