[Tutor] flow problem with a exercise
Roelof Wobben
rwobben at hotmail.com
Sat Aug 21 11:57:06 CEST 2010
From: waynejwerner at gmail.com
Date: Fri, 20 Aug 2010 15:07:56 -0500
Subject: Re: [Tutor] flow problem with a exercise
To: rwobben at hotmail.com
CC: tutor at python.org
On Fri, Aug 20, 2010 at 2:48 PM, Roelof Wobben <rwobben at hotmail.com> wrote:
Oke,
I don''t understand it complety.
return not arg%2
Why use not here ?
I think that arg%2 is True not makes it false.
What happens when you replace arg with a value? % is modulo division, so it just returns the remainder.
2 % 2 = ?
2%2=0
4 % 2 = ?
4%2=0
7 % 2 = ?
7%2=1
11 % 2 = ?
11%2 =1
What is the truth value of 0 and 1?
print 'True' if 0 else 'False'
False
print 'True' if 1 else 'False'
True
So what is the outcome of the following?
result = 2 % 2
print result, not result
if not result:
print 'Even'
if result:
print 'odd'
0 True
Even
So 1 is True and 0 is False according to Python.
Another question.
How can I round outcome of a calculation.
round ( ( t-32)/1.8) does not work because I get a message that there are two arguments.
Outcome = (t-32)/1.8
outcome2 = round (outcome) does not work because the argument must be a string or a number
What is the type of t?
In [39]: t = 3
In [40]: round((t-32)/1.8)
Out[40]: -16.0
In [41]: t = 3.0
In [42]: round((t-32)/1.8)
Out[42]: -16.0
Works fine for me.
Correct,
But I see one wierd thing.
round ((42-32)/1.8) gives a output -16.0 but (42-32)/1.8) gives also -16.0
I was expectting that round will give 16 as output because round (32.0) is the same as round (32.0, 0) so there will be 0 decimals.
And I see one decimal.
Roelof
HTH,
Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100821/00ea43c8/attachment-0001.html>
More information about the Tutor
mailing list