diff --git a/cs171/Lect08/fibo.py b/cs171/Lect08/fibo.py new file mode 100644 index 0000000000000000000000000000000000000000..ca1aeda4091b31edc91e4b5b0fab7aef53fe6e9a --- /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 0000000000000000000000000000000000000000..27946c49e44d4cf89558cc60df6257832ba64776 --- /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 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/cs171/Lect08/readme.py b/cs171/Lect08/readme.py new file mode 100644 index 0000000000000000000000000000000000000000..19f8c7f3eb219e0453e40d119dca1a904c6859b2 --- /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 0000000000000000000000000000000000000000..a03fe209c240fbc9c8dae29ddada7d50085c8037 --- /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 0000000000000000000000000000000000000000..bec144d2665fa6e8765b649c4e8e19eb16266a0e --- /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 0000000000000000000000000000000000000000..061448a8d1383c3b10b99d3b4667be38bd953c3a --- /dev/null +++ b/cs172/Lect08/hello.py @@ -0,0 +1 @@ +print("Hello CS 171")