Wrox Programmer Forums

Need to download code?

View our list of code downloads.

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 November 30th, 2011, 01:30 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 Booleans in this code

Hi, could someone please help me understand why all the True and False in this code? Thanks in advance



Code:
omelet_ingredients = {"egg":2, "mushroom":5, "pepper":1, "cheese":1, "milk":1}
fridge_contents = {"egg":10, "mushroom":10, "pepper":3, "cheese":2, "tomato":4, "milk":15}
have_ingredients =[False]
if fridge_contents["egg"] > omelet_ingredients["egg"]:
    have_ingredients[0] = True
    have_ingredients.append("egg")

if fridge_contents["mushroom"] > omelet_ingredients["mushroom"]:
    if have_ingredients[0] == False:
        have_ingredients[0] = True
    have_ingredients.append("mushroom")

if fridge_contents["pepper"] > omelet_ingredients["pepper"]:
    if have_ingredients[0] == True:
        have_ingredients[0] = False
    have_ingredients.append("pepper")

if fridge_contents["cheese"] > omelet_ingredients["cheese"]:
    if have_ingredients[0] == False:
        have_ingredients[0] = True
    have_ingredients.append("cheese")

if fridge_contents["milk"] > omelet_ingredients["milk"]:
    if have_ingredients[0] == True:
        have_ingredients[0] = False
    have_ingredients.append("milk")

if have_ingredients[0] == False:
    print("I have the ingredients to make an omelet!")
  #2 (permalink)  
Old January 5th, 2012, 03:16 PM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2012
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
Default

Ignore the TRUE and FALSE use in this example, as it is logically flawed and will only confuse you, see it as the example on IF statements in IF statements it is.
The Following User Says Thank You to kimsen1967 For This Useful Post:
Eduardo Tarik (March 15th, 2012)
 


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
Code to save html page source code? Jaymond Flurrie Access VBA 1 December 18th, 2008 10:28 AM
Urgent:hard disk serial code and vb code ivanlaw Pro VB 6 0 July 25th, 2007 05:05 AM
VB: .Exe file, serial code and activation code ivanlaw Pro VB 6 8 July 6th, 2007 06:44 AM
Writing Client Side Script from Code-Behind code sajid_pk Classic ASP Databases 1 January 18th, 2005 12:53 AM
MySQL fields and booleans crapanz MySQL 2 September 21st, 2004 01:24 PM



All times are GMT -4. The time now is 04:21 AM.


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