-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPower.py
More file actions
41 lines (34 loc) · 747 Bytes
/
Power.py
File metadata and controls
41 lines (34 loc) · 747 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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# -*- coding: utf-8 -*-
"""
Created on Tue Jun 13 22:41:13 2017
@author: Марианна
"""
def iterPower(base, exp):
'''
base: int or float.
exp: int >= 0
returns: int or float, base^exp
'''
res = 1
for n in range (1, exp + 1):
res *= base
return res
def recurPower(base, exp):
'''
base: int or float.
exp: int >= 0
returns: int or float, base^exp
'''
if exp == 0:
return 1
elif exp == 1:
return base
else:
return base*recurPower(base, exp-1)
print(iterPower(0.9, 0))
print(iterPower(-6.04, 1))
print(iterPower(3.56, 10))
print('---------------------')
print(recurPower(3.41, 2))
print(recurPower(3.56, 10))
print(recurPower(-7.55, 5))