From eee2e1e7c05525259e9bd1478d7cb56705821d40 Mon Sep 17 00:00:00 2001 From: Louis Date: Thu, 23 Nov 2023 09:06:47 +0100 Subject: [PATCH] vault backup: 2023-11-23 09:06:47 --- Algo/B2/Exercises/Repetitive tutorial.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Algo/B2/Exercises/Repetitive tutorial.md b/Algo/B2/Exercises/Repetitive tutorial.md index 9902adb..aa1311b 100644 --- a/Algo/B2/Exercises/Repetitive tutorial.md +++ b/Algo/B2/Exercises/Repetitive tutorial.md @@ -54,4 +54,21 @@ def exponetial(x: int, n: int) -> int: m *= x n -= 1 return result + +def power(x, n): + if x == 0; + if n == 0: + raise Exception("0 power 0 undefinded") + else: + return 0 + elif x == 1: + return 1 + elif x == -1: + return (n%2)*(-2) + 1 + else: + res = 1 + while n > 0: + res *= x + n -= 1 + return res ```