Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 76 additions & 13 deletions functions_to_test.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,90 @@
# Placeholder functions for Python basics, to be implemented later

def add_numbers(a, b):
pass
return a+b

def find_maximum(a, b, c):
pass
return max(a,b,c)

def is_palindrome(string):
pass
return string[::-1] == string

def count_word_occurrences(text, word):
pass
return text.count(word)

def read_file_lines(filepath):
pass
counter = 0
with open(filepath, "r") as file:
for line in file.readline():
counter += 1
return counter


def factorial(n):
pass
try:
counter = 1
if n < 0:
raise ValueError
elif n == 0 or n == 1:
return counter
else:
for i in range(n, 1, -1):
counter *= i
return counter
except TypeError:
pass

def is_prime(n):
pass
if n < 0 :
raise ValueError
else:
counter = 0
for i in range(1, n+1):
if n % i == 0:
counter += 1
if counter == 2:
return True
else:
return False

def sort_numbers(numbers):
pass

try:
for i in numbers:
if i is int:
if numbers == []:
return []
else:
return sorted(numbers)
else:
raise TypeError
except TypeError:
pass

def factorial(n):
pass
counter = 1
if n < 0:
return ""
elif n == 0 or n == 1:
return counter
else:
for i in range(n, 1, -1):
counter *= i
return counter

def fibonacci(n):
pass
if n == 0:
return None
if n == 1:
return 0
else:
list_of_fib = list()
a, b = 0, 1
for _ in range(n):
list_of_fib.append(a)
a, b = b, a + b
return list_of_fib[-1]



def tower_of_hanoi(n, source, auxiliary, target):

Expand All @@ -52,10 +108,17 @@ def tower_of_hanoi(n, source, auxiliary, target):

class Person:
def __init__(self, name, age):
pass
self.name = name
self.age = age


if __name__ == "__main__":
# Placeholder functions for Python basics, to be implemented later
#to test your functions, you can use the following code
print(add_numbers(3, 5)) #e.g
print(add_numbers(3, 5)) #e.g
print(factorial(0))
# print(sort_numbers([-3, -1, -2]))
print(fibonacci(5))
print(is_prime(3))
print(factorial(9))
print(read_file_lines("database.csv"))