[Tutor] Need some help on "How to Think Like a Computer Scientist: Learning with Python" exercise

Lie Ryan lie.1296 at gmail.com
Wed Mar 31 03:14:54 CEST 2010


On 03/31/2010 04:00 AM, Yahoo Mail wrote:
> Hello All,
>  
> I am competely new in Python programming. When i reading Chapter 4 in
> "How to Think Like a Computer Scientist: Learning with Python" ,
> I am stuck in the exercise 4.
>  
> Here is the question:
>  
> Enter the following expressions into the Python shell:
> 1. True or False
> 2. True and False
> 3. not(False) and True
> 4. True or 7
> 5. False or 7
> 6. True and 0
> 7. False or 8
> 8. "happy" and "sad"
> 9. "happy" or "sad"
> 10. "" and "sad"
> 11. "happy" and ""
> Analyze these results. What observations can you make about values of
> different types and logical operators? Can you write these observations
> in the form of simple /rules/ about and and or expressions?
>  
> I have no problem with 1-4,  but compelely wrong with the rest. Like
> question 5, i throught the  answer is True, but when i type it in IDLE,
> I got 7 instead, question 8 "happy' and 'sad', my answer is True, but
> the answer is 'happy'. Can you please tell me why i am wrong. I really
> appreciate any assistance you can give.

This is python's flavor of short-circuiting. Read the doc at:
>>> help("BOOLEAN")



More information about the Tutor mailing list