From 01560dbbcfe6d0bf7c9ca2acb814b3d0b78a4360 Mon Sep 17 00:00:00 2001 From: Drew Sexton Date: Sat, 14 Nov 2020 22:19:57 -0500 Subject: [PATCH] completed assessment, all tests pass --- main.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 59325b9..b2bdcf3 100644 --- a/main.py +++ b/main.py @@ -9,31 +9,49 @@ def add(x, y): """Add two integers.""" # your code here - return + return x + y def multiply(x, y): """Multiply x with y using the add() function above.""" # your code here - return + res = 0 + for i in range(abs(y)): + res = add(res, abs(x)) + if x < 0 < y or y < 0 < x: + return -res + return res def power(x, n): """Raise x to power n, where n >= 0, using the functions above.""" # your code here - return + res = 1 + for i in range(n): + res = multiply(res, x) + return res def factorial(x): """Compute the factorial of x, where x > 0, using the functions above.""" # your code here - return + res = 1 + for i in range(x, 0, -1): + res = multiply(res, i) + return res def fibonacci(n): """Compute the nth term of fibonacci sequence using the functions above.""" # your code here - return + res = [] + for i in range(n + 1): + if i < 2: + res.append(i) + else: + res.append(add(res[-2], res[-1])) + print(res) + return res[-1] if __name__ == '__main__':