From 8adf91f803f536227b049041c8c4c78b24556405 Mon Sep 17 00:00:00 2001 From: Daniel Moix <dwm69@drexel.edu> Date: Tue, 22 Aug 2023 17:29:57 -0400 Subject: [PATCH] Adding Week 9 lecture --- cs171/Lect08/fibo.py | 10 ++++++++++ cs171/Lect08/fibo_iterative.py | 9 +++++++++ cs171/Lect08/hello.py | 0 cs171/Lect08/readme.py | 22 ++++++++++++++++++++++ cs171/Lect08/sumOfDigits.py | 7 +++++++ cs171/Lect08/summation.py | 7 +++++++ cs172/Lect08/hello.py | 1 + 7 files changed, 56 insertions(+) create mode 100644 cs171/Lect08/fibo.py create mode 100644 cs171/Lect08/fibo_iterative.py create mode 100644 cs171/Lect08/hello.py create mode 100644 cs171/Lect08/readme.py create mode 100644 cs171/Lect08/sumOfDigits.py create mode 100644 cs171/Lect08/summation.py create mode 100644 cs172/Lect08/hello.py diff --git a/cs171/Lect08/fibo.py b/cs171/Lect08/fibo.py new file mode 100644 index 0000000..ca1aeda --- /dev/null +++ b/cs171/Lect08/fibo.py @@ -0,0 +1,10 @@ +def fibo(num): + if num <= 0: + return 0 + if num == 1: + return 1 + else: + return fibo(num - 1) + fibo(num - 2) + +for f in range(1, 100): + print(f, fibo(f)) \ No newline at end of file diff --git a/cs171/Lect08/fibo_iterative.py b/cs171/Lect08/fibo_iterative.py new file mode 100644 index 0000000..27946c4 --- /dev/null +++ b/cs171/Lect08/fibo_iterative.py @@ -0,0 +1,9 @@ +prev = 0 +next = 1 +i = 1 +while i < 100: + print(i, next) + nextNext = prev + next + prev = next + next = nextNext + i += 1 \ No newline at end of file diff --git a/cs171/Lect08/hello.py b/cs171/Lect08/hello.py new file mode 100644 index 0000000..e69de29 diff --git a/cs171/Lect08/readme.py b/cs171/Lect08/readme.py new file mode 100644 index 0000000..19f8c7f --- /dev/null +++ b/cs171/Lect08/readme.py @@ -0,0 +1,22 @@ +def func1(input): + if input % 2 == 0: + answer = func2(input, 2) + else: + answer = func2(input + 1, -2) + return answer + +def func2(input, factor): + return input * factor + +def func3(input): + if input > 0: + answer = input + func3(int(input/2)) + else: + answer = 1 + return answer + +if __name__ == "__main__": + print(func3(5)) + + + \ No newline at end of file diff --git a/cs171/Lect08/sumOfDigits.py b/cs171/Lect08/sumOfDigits.py new file mode 100644 index 0000000..a03fe20 --- /dev/null +++ b/cs171/Lect08/sumOfDigits.py @@ -0,0 +1,7 @@ +def sumOfDigits(number): + if number < 10: + return number + else: + return number % 10 + sumOfDigits(number // 10) + +print(sumOfDigits(507)) \ No newline at end of file diff --git a/cs171/Lect08/summation.py b/cs171/Lect08/summation.py new file mode 100644 index 0000000..bec144d --- /dev/null +++ b/cs171/Lect08/summation.py @@ -0,0 +1,7 @@ +def func(x): + if x <= 0: + return 0 + else: + return func(x - 1) + x + +print(func(0)) \ No newline at end of file diff --git a/cs172/Lect08/hello.py b/cs172/Lect08/hello.py new file mode 100644 index 0000000..061448a --- /dev/null +++ b/cs172/Lect08/hello.py @@ -0,0 +1 @@ +print("Hello CS 171") -- GitLab