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
92 changes: 79 additions & 13 deletions functions_to_test.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,92 @@
# 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
if type(string) == type("stirng"):
if string == string[::-1]:
return True
else:
return False
else:
raise TypeError("Invalid input!")


def count_word_occurrences(text, word):
pass
if type(text) == type(word):
text = text.upper()
word = word.upper()
count = text.count(word)
return count
else:
raise TypeError("Invalid type entered")


def read_file_lines(filepath):
pass
if filepath:
with open(filepath, "r") as f:
file = f.readlines()
return file
else:
raise FileNotFoundError("File not found")


def factorial(n):
pass
fact = n

if type(n) != type(0):
raise TypeError("Invalid type!")
elif n == 0:
return 1
elif n < 0:
raise ValueError("Invalid number!")
for i in range(1, n):
fact = fact * i
return fact


def is_prime(n):
pass
count = 0
if type(n) == type(0):
if n == 1:
return False
elif n < 0:
raise ValueError("Prime not defined for negative numbers")
for i in range(1, n + 1):
if n % i == 0:
count += 1
if count > 2:
return False
else:
return True
elif type(n) != type(0):
raise TypeError("Invalid input!")


def sort_numbers(numbers):
pass
if numbers == []:
return []
for i in numbers:
if type(i) == type(0):
return sorted(numbers)
else:
raise TypeError("Invalid list elements")

def factorial(n):
pass

def fibonacci(n):
pass
fibo_list = [0, 1]

for i in range(n - 1):
fibo_list.append(fibo_list[len(fibo_list) - 2] + fibo_list[len(fibo_list) -1])

return fibo_list[n]


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

Expand All @@ -48,14 +106,22 @@ def tower_of_hanoi(n, source, auxiliary, target):
>>> tower_of_hanoi(3, 'A', 'B', 'C')
[('A', 'C'), ('A', 'B'), ('C', 'B'), ('A', 'C'), ('B', 'A'), ('B', 'C'), ('A', 'C')]
"""

pass

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

if type(name) != type("string"):
raise TypeError
if type(age) != type(0):
raise TypeError


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(read_file_lines("nkulu.txt"))