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 November 30th, 2011, 01:30 PM
Registered User
 
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!")
 
Old January 5th, 2012, 03:16 PM
Registered User
 
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)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Code to save html page source code? Jaymond Flurrie Access VBA 2 July 2nd, 2019 06:04 PM
Urgent:hard disk serial code and vb code ivanlaw Pro VB 6 0 July 25th, 2007 04:05 AM
VB: .Exe file, serial code and activation code ivanlaw Pro VB 6 8 July 6th, 2007 05: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 12:24 PM





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