-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsession_2.py
65 lines (47 loc) · 1.3 KB
/
session_2.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def reverse_star_printer(number):
print('*' * number)
if number != 1:
reverse_star_printer(number -1)
def power(number, power):
output = 1
for i in range(power):
output = output * number
return output
def reverse_power(number, power):
output = number
if (power > 1):
output = output * reverse_power(number, power-1)
return output
def factorail(number):
result = 1
for i in range(number+1):
if i == 0 or i == 1:
result *= 1
else:
result *= i
return result
def reverse_factorail(number):
if number == 0:
return 1
elif number == 1:
return number
else:
result = 0
result = number * reverse_factorail(number - 1)
return result
def test_factorail():
assert factorail(0) == 1
assert factorail(1) == 1
assert factorail(2) == 2
assert factorail(3) == 6
def test_reverse_factorail():
assert reverse_factorail(0) == 1
assert reverse_factorail(1) == 1
assert reverse_factorail(2) == 2
assert reverse_factorail(3) == 6
def test_power():
assert power(3,2) == 9
assert power(3,3) == 27
#print(reverse_power(3, 3))
print(factorail(5))
#print(reverse_factorail(4))