From 83d51105f18734bcfbaf01af3fe6040b77e8d8c7 Mon Sep 17 00:00:00 2001 From: Aigerim Kenzhebekova Date: Fri, 16 Jan 2026 15:00:34 -0500 Subject: [PATCH 1/2] added square and cube functions --- calculator.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/calculator.py b/calculator.py index 9f8b6b8..2f35785 100644 --- a/calculator.py +++ b/calculator.py @@ -13,6 +13,10 @@ def subtract(a, b): def divide(a, b): return a / b -print("I'm going use the calculator functions to multiply 5 and 6") -x = multiply(5,6) -print(x) \ No newline at end of file + +def square(x): + return x * x + + +def cube(x): + return x * x * x \ No newline at end of file From 27c0fdefd378c24f30c1fdfc9a673e1a7f0ce62e Mon Sep 17 00:00:00 2001 From: Aigerim Kenzhebekova Date: Fri, 16 Jan 2026 15:02:57 -0500 Subject: [PATCH 2/2] added the square n times function --- calculator.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/calculator.py b/calculator.py index 2f35785..0357be9 100644 --- a/calculator.py +++ b/calculator.py @@ -19,4 +19,26 @@ def square(x): def cube(x): - return x * x * x \ No newline at end of file + return x * x * x + + +def square_n_times(number, n): + """Square `number` repeatedly `n` times and return the sum. + + On each iteration, the current value is squared and added to the total. + For example, with number=2 and n=3: + - iteration 1: 2^2 = 4 + - iteration 2: 4^2 = 16 + - iteration 3: 16^2 = 256 + Sum returned: 4 + 16 + 256 = 276 + + If `n` is 0, returns 0. Expects non-negative integer `n`. + """ + if n < 0: + raise ValueError("n must be a non-negative integer") + result = 0 + current = number + for _ in range(n): + current = current * current + result += current + return result \ No newline at end of file