8
Contributors
13
Replies
35
Views
9 Years
Discussion Span
Last Post by pythonBasic
Featured Replies
  • 1

    [QUOTE=RMartins;537916]but how can i prove for example that the result of sqrt(n) is an integer?[/QUOTE] You can do this (maybe is there more elegant way) [CODE] if math.sqrt(n) == float(int(math.sqrt(n))): print "sqrt(n) is an integer" [/CODE] Read More

0

for Ex.

x = 10
print x
print type (x)

it should show you that x ia 10 and its interger "<type 'int'>".

0

but how can i prove for example that the result of sqrt(n) is an integer?

0

The function sqrt(x) returns a float:

import math

x = 9
y = math.sqrt(x)

print y, type(y)  # 3.0 <type 'float'>

If you want the result to be an integer use int(y).

0

You can also use isinstance() method to check whether an object is an instance or type of a class[everything in Python is an object]

>>> v=9
>>> if isinstance(v, int):
	print 'int'

int
1

but how can i prove for example that the result of sqrt(n) is an integer?

You can do this (maybe is there more elegant way)

if math.sqrt(n) == float(int(math.sqrt(n))):
    print "sqrt(n) is an integer"
Votes + Comments
nice work
0

does anybody knows why this function doesn´t work very well:

f=lambda n: reduce(lambda x,y:x**2+y**2, map(int,str(n)))

I want that this function add the square of the digits of a number

an example of what i want:

f(442)=4**2+4**2+2**2=36

0

Create a new thread for this question. People with questions like yours will often search on the post name, and it's helpful to have it separate from the lead question.

Jeff

0

can some one suggest me below
If i need to fire http request multiple times in python.Please suggest me steps as i am new to python

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.