1.计算平方
def power(x, n):
s = 1
while n > 0:
n = n - 1
s = s * x
return s
print(power(5,2))
print(power(5,3))
2.计算10以内的平方
g = (x * x for x in range(10))
for i in g:
print(i)
3.计算绝对值
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))