def mypower (x,n):
if not isinstance(n,int):
raise TypeError('bad operand type')
s=1
if n>0:
while n>0:
n=n-1
s=s*x
return s
if n<0:
while n<0:
n=n+1
s=s*(1/x)
a=mypower(2,-2)
print(a)
Sign in to make a reply
逸
def mypower (x,n):
if not isinstance(n,int):
raise TypeError('bad operand type')
s=1
if n>0:
while n>0:
n=n-1
s=s*x
return s
if n<0:
while n<0:
n=n+1
s=s*(1/x)
return s
a=mypower(2,-2)
print(a)