Jump to content

Test integerness: Difference between revisions

→‎{{header|Python}}: Updated to handle ints, floats, and complex types.
(→‎{{header|Python}}: Updated to handle ints, floats, and complex types.)
Line 23:
 
=={{header|Python}}==
{{incomplete}}
<lang python>>>> def isint(f):
return complex(f).imag == 0 and int(complex(f).real) == complex(f).real
 
>>> [isint(f) for f in (1.0, 2, (3.0+0.0j), 4.1, (3+4j), (5.6+0j))]
>>> isint(3.14)
[True, True, True, False, False, False]
False
>>> isint(3.0)
True
>>> </lang>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.