<span class="Apple-style-span" style="font-family: Helvetica; font-size: medium; ">Isn&#39;t one of the unsolved millenium prize problems one that includes the ability to find all of the prime numbers? I&#39;m not sure if your program is possible if the input number is large.</span><div style="font-family: Helvetica; font-size: medium; ">
<br></div><div style="font-family: Helvetica; font-size: medium; ">But to check if a number x is an int, just do this:</div><div style="font-family: Helvetica; font-size: medium; "><br></div><div style="font-family: Helvetica; font-size: medium; ">
x == int(x)</div><div style="font-family: Helvetica; font-size: medium; "><br></div><div style="font-family: Helvetica; font-size: medium; "><br></div><div style="font-family: Helvetica; font-size: medium; ">Rachel</div><div style="font-family: Helvetica; font-size: medium; ">
<br></div><br><div class="gmail_quote">On Tue, May 31, 2011 at 2:38 PM, Hugo Arts <span dir="ltr">&lt;<a href="mailto:hugo.yoshi@gmail.com">hugo.yoshi@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="im">On Tue, May 31, 2011 at 11:30 PM, Joel Goldstick<br>
&lt;<a href="mailto:joel.goldstick@gmail.com">joel.goldstick@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt;<br>
&gt; <a href="http://stackoverflow.com/questions/1265665/python-check-if-a-string-represents-an-int-without-using-try-except" target="_blank">http://stackoverflow.com/questions/1265665/python-check-if-a-string-represents-an-int-without-using-try-except</a><br>

&gt;<br>
&gt; def RepresentsInt(s):<br>
&gt;<br>
&gt;     try:<br>
&gt;         int(s)<br>
&gt;<br>
&gt;         return True<br>
&gt;     except ValueError:<br>
&gt;<br>
&gt;         return False<br>
&gt;<br>
&gt;&gt;&gt;&gt; print RepresentsInt(&quot;+123&quot;)<br>
&gt;<br>
&gt; True<br>
&gt;&gt;&gt;&gt; print RepresentsInt(&quot;10.0&quot;)<br>
&gt;<br>
&gt; False<br>
&gt;<br>
<br>
</div>For strings, that works, but not for integers:<br>
<br>
&gt;&gt;&gt; int(10.0)<br>
10<br>
<br>
And if you want to check if one number is divisible by another, you&#39;re<br>
not going to call it on strings.<br>
<br>
A better way is to use the modulo operator, which gives the remainder<br>
when dividing:<br>
<br>
&gt;&gt;&gt; a = 6<br>
&gt;&gt;&gt; a % 3<br>
0<br>
&gt;&gt;&gt; a % 4<br>
2<br>
<br>
So, if the remainder is zero the left operand is divisible by the right one.<br>
<font color="#888888"><br>
Hugo<br>
</font><div><div></div><div class="h5">_______________________________________________<br>
Tutor maillist  -  <a href="mailto:Tutor@python.org">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
</div></div></blockquote></div><br>