programming logical functions: myand, myor and mynot
Gernot
headroom02 at gmx.de
Sun Nov 18 17:14:17 EST 2001
"Eddie Corns" <eddie at holyrood.ed.ac.uk> schrieb im Newsbeitrag
news:9t3p3q$rvl$1 at scotsman.ed.ac.uk...
> "Gernot" <headroom02 at gmx.de> writes:
>
[deleted]
>
> I think you've correctly worked out that AND is equivalent to the nested
if
> statements but it's not clear from the example what you're trying to do.
> If you are in fact trying to evaluate input from the user you need to
choose a
> representation for true and false (such as 't' and 'f') and make explicit
> tests for these.
> If the input is just for testing and you're trying to understand how myand
> works, then you just need to think of 'x' and 'y' as _expressions_, which
will
> be evaluated to true or false in the right context (I can't think of
another
> way of saying this as a hint rather than giving the answer outright).
That´s right, but I did not have the idea on my own, some students opened my
eyes, they gave me this program (it is done with your idea):
#######################
def truth ():
return "oneword" != "anotherword"
def antitruth ():
return "oneword" == "anotherword"
def myand (a,b):
if (a == truth()):
if (b == truth()):
return truth()
else:
return antitruth()
else:
return antitruth()
def myor (a,b):
if (a == truth()):
return truth()
else:
if (b == truth()):
return truth()
else:
return antitruth()
def mynot (a):
if (a == truth()):
return antitruth()
else:
return truth()
def usethistoprint (a):
if (a == truth()):
print "True"
else:
print "False"
##########################
I think, that is pretty implementation, I hope I will be able to do this on
my own, soon.
Thank you for your comment.
Gernot
More information about the Python-list
mailing list