fonction in python

mensanator at aol.com mensanator at aol.com
Tue Jul 4 13:17:59 EDT 2006


aliassaf wrote:
> Hello,
>
> If we write = x^2  and if I give to the program the values of x, it will
> going to calculate the values of y, and also for x.
>
> But it is possible ? that is if I give to the program the values of X and Y,
> it will indicate to me the relation between the two variables, in the other
> hand if I look to the program x=2 y=4, x=3 y=9 ect... it is going to show me
> that f (t)!!!

You can use the GMPY module to determine square & power relationships:

>>> import gmpy
>>> for n in range(20):
	print n,
	if gmpy.is_square(n):
		print True,
	else:
		print False,
	if gmpy.is_power(n):
		print True
	else:
		print False


0 True True
1 True True
2 False False
3 False False
4 True True
5 False False
6 False False
7 False False
8 False True
9 True True
10 False False
11 False False
12 False False
13 False False
14 False False
15 False False
16 True True
17 False False
18 False False
19 False False

9 is both a power and a square whereas 8 is a power but not a square.


>
> Thanks
>
> --
> View this message in context: http://www.nabble.com/fonction-in-python-tf1889102.html#a5164997
> Sent from the Python - python-list forum at Nabble.com.




More information about the Python-list mailing list