Hackerrank Day 17: More Exceptions

#Write your code here
class Calculator:
    def power(self, n, p):
        if (n<0 or p<0):
            raise Exception("n and p should be non-negative")
        else:
            return pow(n,p)


myCalculator=Calculator()
T=int(input())
for i in range(T):
    n,p = map(int, input().split())
    try:
        ans=myCalculator.power(n,p)
        print(ans)
    except Exception as e:
        print(e)   
发布了128 篇原创文章 · 获赞 90 · 访问量 4869

猜你喜欢

转载自blog.csdn.net/weixin_45405128/article/details/103931214