[Tutor] flow problem with a exercise

Wayne Werner waynejwerner at gmail.com
Fri Aug 20 22:07:56 CEST 2010


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 = ?
4 % 2 = ?
7 % 2 = ?
11 % 2 = ?

What is the truth value of 0 and 1?

print 'True' if 0 else 'False'
print 'True' if 1 else 'False'

So what is the outcome of the following?

result = 2 % 2
print result, not result
if not result:
   print 'Even'
if result:
   print 'odd'



>
> 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.

HTH,
Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100820/ccc2ce04/attachment.html>


More information about the Tutor mailing list