-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday17.py
More file actions
27 lines (21 loc) · 794 Bytes
/
day17.py
File metadata and controls
27 lines (21 loc) · 794 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""
Write a Calculator class with a single method: int power(int,int). The power method takes two integers,
n and p, as parameters and returns the integer result of n**p. If either n or p is negative,
then the method must throw an exception with the message: n and p should be non-negative.
Note: Do not use an access modifier (e.g.: public) in the declaration for your Calculator class.
"""
#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')
return 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)