Skip to content

Commit 90ded27

Browse files
authored
Merge pull request #2 from code4policy/new-functions
Added squaring, cubing, and square n times functions
2 parents 2e222f9 + b78125b commit 90ded27

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

calculator.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
1-
def multiply(a,b):
2-
return a * b
3-
41
def add(a,b):
52
return a+b
63

74
def subtract(a,b):
85
return a-b
96

7+
def multiply(a,b):
8+
return a * b
9+
1010
def divide(a,b):
1111
return a/b
1212

13+
def square(a):
14+
return a*a
15+
16+
def cube(a):
17+
return a*a*a
18+
19+
def square_n_times(number, n):
20+
if n < 0:
21+
raise ValueError("n must be non-negative number")
22+
total = 0
23+
value = number
24+
for _ in range(n):
25+
value = value * value
26+
total += value
27+
return total
28+
1329
print("I'm going use the calculator functions to multiply 5 and 6")
1430
x = multiply(5,6)
1531
print(x)

0 commit comments

Comments
 (0)