Skip to content

Commit 50ad8da

Browse files
authored
Merge pull request #2 from code4policy/calculator-advanced
Add square, cube, and square_n_times functions
2 parents 211b8ef + 3515f62 commit 50ad8da

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

calculator.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,20 @@ def divide(a,b):
1313

1414
print("I'm going use the calculator functions to multiply 5 and 6")
1515
x = multiply(5,6)
16-
print(x)
16+
print(x)
17+
18+
def square(x):
19+
return x ** 2
20+
21+
22+
def cube(x):
23+
return x ** 3
24+
25+
26+
def square_n_times(number, n):
27+
total = 0
28+
current = number
29+
for _ in range(n):
30+
current = square(current)
31+
total += current
32+
return total

0 commit comments

Comments
 (0)