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 ```