On Sep 25, 2008, at 5:43 PM, William Stein wrote:
>
> On Thu, Sep 25, 2008 at 5:33 PM, Quicksilver_Johny
> <[EMAIL PROTECTED]> wrote:
>>
>> If c=sqrt(a^2+b^2)
>> How would I check if c is an integer in order to get a true/false
>> value.
>> I tried is_Integer(ZZ(c)), this returns true when c is an integer,
>> but
>> ZZ(c) returns an error when c is not an integer.
>
> Try using Python's try/except:
>
> try:
> ZZ(c)
> # c is an integer
> except TypeError:
> # c isn't an integer
These is_* sure are causing a lot of confusion lately...
Rational numbers also have an is_integral method, so you could also do
c=sqrt(a^2+b^2)
if c.is_integral():
# c is an integer
- Robert
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---