Way of learning python: computing

1. Calculate the square
Power DEF (X, n-): 
S =. 1
the while n-> 0:
n-n-= -. 1
S * = S X
return S

Print (Power (5,2))
Print (Power (5,3))

2. calculate 10 within the square
= G (X * X for X in Range (10)) 
for I in G:
Print (I)

3. calculates an absolute value
def my_abs(x):
if x >= 0:
return x
else:
return -x

print(my_abs(-9))

from def_01 import my_abs

print(my_abs(-9))


Guess you like

Origin www.cnblogs.com/Arabi/p/11573674.html