[Tutor] flow problem with a exercise
Dave Angel
davea at ieee.org
Sat Aug 21 12:42:33 CEST 2010
You need to figure out how to get your email program to do quoting. As
it stands, there's no good way to tell what part of the following
message was from you, and what part was from wayne, or maybe others.
Probably all you need to do is to do a reply-all to the message, and
it'll mark the existing text with a ">" symbol. Then make sure
everything you type is *not* quoted.
Roelof Wobben wrote:
>
>
>
> From: waynejwerner at gmail.com
> <snip>
>
> 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.
>
>
>
No, True is a specific object that differs from all other objects.
Likewise False. However, other objects, including especially integers,
lists, and strings, can be used in a boolean context, and there are
specific rules that decide whether a given object will be used as true
(lowercase) or false. For integers values, all nonzero items are
considered true, while zero is considered false.
>
>
>
> 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
You're confusing the operation of round() with the operation of
converting to a string for printing. Round changes a floating point
(binary) value to have a certain quantization, which approximates what
you might want to print. It does not, however, affect the way print
will subsequently deal with that floating point number. It's no
different than when you use a numeric literal with varying amounts of
apparent precision.
x = 4.2
x = 4.20
x = 4.2000000000
all produce precisely the same floating point object.
DaveA
More information about the Tutor
mailing list