<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:Tahoma
}
--></style>
</head>
<body class='hmmessage'>
<BR>&nbsp;<BR>
<HR id=stopSpelling>
From: waynejwerner@gmail.com<BR>Date: Fri, 20 Aug 2010 15:07:56 -0500<BR>Subject: Re: [Tutor] flow problem with a exercise<BR>To: rwobben@hotmail.com<BR>CC: tutor@python.org<BR><BR>
<DIV class=ecxgmail_quote>On Fri, Aug 20, 2010 at 2:48 PM, Roelof Wobben <SPAN dir=ltr>&lt;<A href="mailto:rwobben@hotmail.com">rwobben@hotmail.com</A>&gt;</SPAN> wrote:<BR>
<BLOCKQUOTE style="BORDER-LEFT: #ccc 1px solid; PADDING-LEFT: 1ex" class=ecxgmail_quote>
<DIV>Oke, <BR>&nbsp;<BR>I don''t understand it complety.<BR>&nbsp;<BR>return not arg%2 <BR>&nbsp;<BR>Why use not here&nbsp;?<BR>&nbsp;<BR>I think that&nbsp;arg%2&nbsp;is True not makes it false. <BR></DIV></BLOCKQUOTE>
<DIV><BR></DIV>
<DIV>What happens when you replace arg with a value? % is modulo division, so it just returns the remainder.</DIV>
<DIV><BR></DIV>
<DIV>2 % 2 = ?</DIV>
<DIV><FONT style="BACKGROUND-COLOR: #ffffff" color=#c00000>2%2=0 </FONT></DIV>
<DIV><FONT color=#c00000></FONT>&nbsp;</DIV>
<DIV>4 % 2 = ?</DIV>
<DIV><FONT color=#c00000>4%2=0</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>7 % 2 = ?</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT color=#c00000>7%2=1 </FONT></DIV>
<DIV><FONT color=#c00000></FONT>&nbsp;</DIV>
<DIV>11 % 2 = ?</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT color=#c00000>11%2 =1 </FONT><BR></DIV>
<DIV>What is the truth value of 0 and 1?</DIV>
<DIV><BR></DIV>
<DIV>print 'True' if 0 else 'False'</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT color=#c00000>False </FONT></DIV>
<DIV><FONT color=#c00000></FONT>&nbsp;</DIV>
<DIV>print 'True' if 1 else 'False'</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT color=#c00000>True</FONT><BR></DIV>
<DIV>So what is the outcome of the following?</DIV>
<DIV><BR></DIV>
<DIV>result = 2 % 2</DIV>
<DIV>print result, not result</DIV>
<DIV>if not result:</DIV>
<DIV>&nbsp;&nbsp; print 'Even'</DIV>
<DIV>if result:</DIV>
<DIV>&nbsp;&nbsp; print 'odd'</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT color=#c00000>0&nbsp; True</FONT></DIV>
<DIV><FONT color=#c00000>Even </FONT></DIV>
<DIV><FONT color=#c00000></FONT>&nbsp;</DIV>
<DIV><FONT color=#c00000>So 1 is True and 0 is False according to Python.</FONT></DIV>
<DIV><BR></DIV>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE style="BORDER-LEFT: #ccc 1px solid; PADDING-LEFT: 1ex" class=ecxgmail_quote>
<DIV>&nbsp;<BR>Another question.<BR>&nbsp;<BR>How can I round outcome of a calculation.<BR>&nbsp;<BR>round ( ( t-32)/1.8) does not work because&nbsp;I get a message that there are two arguments.<BR>&nbsp;<BR>Outcome = (t-32)/1.8<BR>outcome2 = round (outcome) does not work because the argument must be a string or a number&nbsp;</DIV></BLOCKQUOTE>
<DIV><BR></DIV>
<DIV>What is the type of t?</DIV>
<DIV><BR></DIV>
<DIV>&nbsp;In [39]: t = 3</DIV>
<DIV><BR></DIV>
<DIV>In [40]: round((t-32)/1.8)</DIV>
<DIV>Out[40]: -16.0</DIV>
<DIV><BR></DIV>
<DIV>In [41]: t = 3.0</DIV>
<DIV><BR></DIV>
<DIV>In [42]: round((t-32)/1.8)</DIV>
<DIV>Out[42]: -16.0</DIV>
<DIV><BR></DIV>
<DIV>Works fine for me.</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT color=#c00000>Correct, </FONT></DIV>
<DIV><FONT color=#c00000>But I see one wierd thing.</FONT></DIV>
<DIV><FONT color=#c00000></FONT>&nbsp;</DIV>
<DIV><FONT color=#c00000>round ((42-32)/1.8) gives&nbsp;a output -16.0 but (42-32)/1.8) gives also -16.0 </FONT></DIV>
<DIV><FONT color=#c00000>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.</FONT></DIV>
<DIV><FONT color=#c00000>And I see one decimal.</FONT></DIV>
<DIV><FONT color=#c00000></FONT>&nbsp;</DIV>
<DIV><FONT color=#c00000>Roelof</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><BR></DIV>
<DIV>HTH,</DIV>
<DIV>Wayne</DIV></DIV>                                               </body>
</html>