Skip to content

Commit bf83b44

Browse files
authored
Merge pull request #2 from code4policy/square-and-cube
Add square, cube, and square_n_times functions
2 parents fedb647 + f587a5b commit bf83b44

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

calculator.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,24 @@ def divide(a,b):
1313
print("I'm going use the calculator functions to multiply 5 and 6")
1414
x = multiply(5,6)
1515
print(x)
16+
17+
def square(x):
18+
"""Return x squared."""
19+
return x ** 2
20+
21+
22+
def cube(x):
23+
"""Return x cubed."""
24+
return x ** 3
25+
26+
def square_n_times(number, n):
27+
"""Square the number n times and return the sum."""
28+
total = 0
29+
current = number
30+
31+
for _ in range(n):
32+
current = current ** 2
33+
total += current
34+
35+
return total
36+

0 commit comments

Comments
 (0)