File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change 13
13
"""
14
14
15
15
16
- def power (n : int , p : int ) -> int :
17
- if p == 0 :
16
+ def power (base : int , exponent : int ) -> int :
17
+ if exponent == 0 :
18
18
return 1
19
19
else :
20
- return n * power (n , (p - 1 ))
20
+ return base * power (base , (exponent - 1 ))
21
21
22
22
23
23
if __name__ == "__main__" :
24
- n = int (input ("Enter the base: " ))
25
- p = int (input ("Enter the exponent: " ))
24
+ base = int (input ("Enter the base: " ))
25
+ exponent = int (input ("Enter the exponent: " ))
26
26
27
- result = power (n , abs (p ))
28
- if p < 0 :
27
+ result = power (base , abs (exponent ))
28
+ if exponent < 0 :
29
29
newResult = 1 / result
30
- print ("{} to the power of {}: {}" .format (n , p , newResult ))
30
+ print ("{} to the power of {}: {}" .format (base , exponent , newResult ))
31
31
else :
32
- print ("{} to the power of {}: {}" .format (n , p , result ))
32
+ print ("{} to the power of {}: {}" .format (base , exponent , result ))
You can’t perform that action at this time.
0 commit comments