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
68 changes: 54 additions & 14 deletions functions_to_test.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,71 @@
# Placeholder functions for Python basics, to be implemented later
import string

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 == string[::-1]


def count_word_occurrences(text, word):
pass
if type(text) != str or type(word) != str:
raise TypeError("Need to be a string")

text = text.lower().split()
word = word.lower()

return text.count(word)

def read_file_lines(filepath):
pass
with open(filepath, 'r') as f:
return f.readlines()

def factorial(n):
pass
if n == 1 or n == 0:
return 1
x = 1
for i in range(1, n+ 1):
x *= i
return x

def is_prime(n):
pass
if n < 0:
raise ValueError("Prime not defined for negative numbers")
if n <= 1:
return False
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
return False
return True


def sort_numbers(numbers):
pass
numbers = []
return numbers.sort(ascii)


def factorial(n):
pass

if n < 0:
return ""
if type(n) != int:
raise TypeError('Invalid input')
if n < 0:
raise ValueError("Invalid input type")
x = 1
for i in range(1, n+ 1):
x *= i
return x

def fibonacci(n):
pass
if n == 0:
return 0
if n == 1:
return 1
return fibonacci(n - 1) + fibonacci(n - 2)

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

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

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

if type(age) != int or type(name) != str:
raise TypeError('Age should only be integer, nae can only be a string')
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