Madhan-Alagarsamy commited on
Commit
e1dfd79
·
verified ·
1 Parent(s): abf4560

Upload 1.py

Browse files
Files changed (1) hide show
  1. 1.py +19 -0
1.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def power(x, n):
2
+ if n == 0:
3
+ return 1
4
+ else:
5
+ return x * power(x, n - 1)
6
+
7
+ print("\tComputing power function using trivial recursion (x^n)")
8
+ print("\t-------------------------------------------------")
9
+
10
+ print("Input")
11
+ print("------")
12
+ x = int(input("Enter the base value x: "))
13
+ n = int(input("Enter the exponential value n: "))
14
+
15
+ r = power(x, n)
16
+
17
+ print("Output")
18
+ print("-------")
19
+ print("The value of", x, "power", n, "=", r)