Python Day 17 : More Exceptions | HackerRank 30 Days of Code Solutions


 Code:

#Write your code here
class e(Exception):
    "n and p should be non-negative"


class Calculator():
    def power(self, n, p):
        try:
            if n | p < 0:
                raise e

            else:
                return (n ** p)
        except e:
            return ("n and p should be non-negative")

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)   
AJ Blogs

Hello everyone, My name Arth and I like to write about what I learn. Follow My Website - https://sites.google.com/view/aj-blogs/home

Post a Comment

Previous Post Next Post
Best Programming Books

Facebook

AJ Facebook
Checkout Our Facebook Page
AJ Blogs
Checkout Our Instagram Page