Re: [Tutor] need help with conditionals

2009-09-26 Thread kevin parks


On Sep 26, 2009, at 11:42 PM, Alan Gauld wrote:



"Kent Johnson"  wrote


It appears to be
http://openbookproject.net/thinkCSpy/ch04.html


So it is, Thats a shame CSpy is one of my favourite "competitors" :-)

Pity it's apparently encouraging the use of eval like this with no  
caveat.


But to the OP, keep with it, its not a bad tutorial, shame about  
this exercise!





Perhaps worth alerting the author? He's a nice guy and i e-mailed him  
many moons ago when i was working through that book with some concerns  
i had. He was really receptive and grateful to get feed back and was  
quick to make changes if he thought they would improv the text. A  
super good dude and it seems, a top notch educator. He tends to credit  
*everyone* who sends in a suggestion, no matter how minor.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] need help with conditionals

2009-09-26 Thread Kent Johnson
On Sat, Sep 26, 2009 at 3:59 AM, Alan Gauld  wrote:
> What are you using for a tutorial?

It appears to be
http://openbookproject.net/thinkCSpy/ch04.html

Kent
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] need help with conditionals

2009-09-26 Thread Alan Gauld


"Kent Johnson"  wrote


It appears to be
http://openbookproject.net/thinkCSpy/ch04.html


So it is, Thats a shame CSpy is one of my favourite "competitors" :-)

Pity it's apparently encouraging the use of eval like this with 
no caveat.


But to the OP, keep with it, its not a bad tutorial, shame about 
this exercise!



--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] need help with conditionals

2009-09-26 Thread Alan Gauld


 wrote

been really frustrating me. Here's a copy of the problem, and sorry if 
its really
long but its the end question about the logically equivalent expressions 
I'm

stuck on. Anyways, heres a copy of the problem


First send us the real code you have used not a copy of your homework.

And secondly send us the complete error message not a summary.
Python error messages are extremely helpful once you learn how
to read them.

Then we might be able to help.

As Corey said my tutorial contains some stuff on understanding
booleans, but the most useful section for truth tables is in the
Functional Programming topic in the Advanced section.

But this question actually has nothing to do with conditionals
or booleans! :-)

The following Python script prints out the truth table for the any 
boolean

expression in two variables: p and q:

expression = raw_input("Enter a boolean expression in two variables, p 
and q: ")


print " p  q  %s"  % expression
length = len( " p  q  %s"  % expression)
print length*"="

for p in True, False:
   for q in True, False:
   print "%-7s %-7s %-7s" % (p, q, eval(expression))
You will learn how this script works in later chapters. For now, you will 
use it to

learn about boolean expressions. Copy this program to a file named
p_and_q.py,


Thats a terrible name BTW it would be better to call it truthtable.py!


from p_and_q import *


And this is bad practice!

What are you using for a tutorial?
If its not for a class I would consider finding another...

Use the truth_table functions with the following boolean expressions, 
recording

the truth table produced each time:

not(p or q)
not(p and q)
not(p) or not(q)
not(p) and not(q)


Also show us a cut n pasdte of you running the program - so we can see
what you are typing as input. Using eval() like this is very prone to user 
error

and also considered bad practice!

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] need help with conditionals

2009-09-25 Thread Lie Ryan

wrobl...@cmich.edu wrote:
Hello all, 
I am still very new to Python and am working on conditionals. Im stuck on this 
problem and I'm sorry if this is something really simple that I'm missing but its 
been really frustrating me. Here's a copy of the problem, and sorry if its really 
long but its the end question about the logically equivalent expressions I'm 
stuck on. Anyways, heres a copy of the problem




it works for me...

"""
Python 2.6.1 (r261:67517, Dec  4 2008, 16:51:00) [MSC v.1500 32 bit 
(Intel)] on

win32
Type "help", "copyright", "credits" or "license" for more information.
>>> def truth_table(expression):
... print " p  q  %s"  % expression
... length = len( " p  q  %s"  % expression)
... print length*"="
... for p in True, False:
... for q in True, False:
... print "%-7s %-7s %-7s" % (p, q, eval(expression))
...
>>> truth_table("p or q")
 p  q  p or q
=
TrueTrueTrue
TrueFalse   True
False   TrueTrue
False   False   False
>>> truth_table("not(p) and not(q)")
 p  q  not(p) and not(q)

TrueTrueFalse
TrueFalse   False
False   TrueFalse
False   False   True
>>> truth_table("not(p or q)")
 p  q  not(p or q)
==
TrueTrueFalse
TrueFalse   False
False   TrueFalse
False   False   True
>>> truth_table("p and q")
 p  q  p and q
==
TrueTrueTrue
TrueFalse   False
False   TrueFalse
False   False   False

"""

How are you calling the truth_table()?

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] need help with conditionals

2009-09-25 Thread christopher . henk
> Hello all, 
> I am still very new to Python and am working on conditionals. Im stuck 
on this 
> problem and I'm sorry if this is something really simple that I'm 
missing but its 
> been really frustrating me. Here's a copy of the problem, and sorry if 
its really 
> long but its the end question about the logically equivalent expressions 
I'm 
> stuck on. Anyways, heres a copy of the problem
> 
> ---
> 


> >>> from p_and_q import *
> >>> truth_table("p or q")


Are you calling the function as shown above?



> 
> Whenever I try to enter the expressions listed into the prompt it tells 
me the 
> string object is not callable


It would be helpful if you showed us exactly what you type into the prompt 
and the exact error you get.  You should be calling the function as it is 
shown in the problem.
Assuming the function is entered and imported correctly you should get a 
true table output.

two examples:
>>> truth_table("p or q")
 p  q  p or q
=
TrueTrueTrue
TrueFalse   True
False   TrueTrue
False   False   False
>>> truth_table("not(p or q)")
 p  q  not(p or q)
==
TrueTrueFalse
TrueFalse   False
False   TrueFalse
False   False   True

Without a bit more info its hard to guess what is happening.

Chris___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor