From f587a5b61901659ba3a87fc6d54840428afee987 Mon Sep 17 00:00:00 2001 From: mandy7am Date: Sun, 18 Jan 2026 14:54:53 -0500 Subject: [PATCH] Add square, cube, and square_n_times functions --- calculator.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/calculator.py b/calculator.py index d4e1195..05ef9d3 100644 --- a/calculator.py +++ b/calculator.py @@ -13,3 +13,24 @@ def divide(a,b): print("I'm going use the calculator functions to multiply 5 and 6") x = multiply(5,6) print(x) + +def square(x): + """Return x squared.""" + return x ** 2 + + +def cube(x): + """Return x cubed.""" + return x ** 3 + +def square_n_times(number, n): + """Square the number n times and return the sum.""" + total = 0 + current = number + + for _ in range(n): + current = current ** 2 + total += current + + return total +