diff --git a/exercises/01loop.py b/exercises/01loop.py index f5c5998..a9e2b4c 100644 --- a/exercises/01loop.py +++ b/exercises/01loop.py @@ -13,3 +13,12 @@ # > Hello there # > Hello there # > Hello there + +def p_times(statement, num): + i = 0 + while i < num: + print(statement) + i +=1 + + +p_times('test', 4) \ No newline at end of file diff --git a/exercises/02letter_count.py b/exercises/02letter_count.py index db07700..a5c2d47 100644 --- a/exercises/02letter_count.py +++ b/exercises/02letter_count.py @@ -26,3 +26,15 @@ # letter_count('banana') # # > {'a': 3, 'b': 1, 'n': 2} + +def letter_count(string): + dd = {} + for char in string: + if char in dd: + dd[char] += 1 + else: + dd[char] = 1 + + return dd + +print(letter_count('banana')) \ No newline at end of file diff --git a/exercises/03print_contacts.py b/exercises/03print_contacts.py index 5f0c52e..cfffa87 100644 --- a/exercises/03print_contacts.py +++ b/exercises/03print_contacts.py @@ -20,3 +20,10 @@ 'Lenny': '444-444-4444', 'Daniel': '777-777-7777' } + + +def print_contacts(contracts): + for name in contacts: + print(f'{name} has a phone number! Its {contacts[name]}') + +print_contacts(contacts) \ No newline at end of file diff --git a/exercises/04multiply_by.py b/exercises/04multiply_by.py index 39b7a30..ddcc013 100644 --- a/exercises/04multiply_by.py +++ b/exercises/04multiply_by.py @@ -10,3 +10,11 @@ # multiply_by([1, 2, 3], 5) # # > [5, 10, 15] + +def multiply_by(li, num): + for i in range(len(li)): + li[i] *= num + + return li + +print(multiply_by([1, 2, 3], 5)) \ No newline at end of file diff --git a/exercises/05factorial.py b/exercises/05factorial.py index 7a1f1be..f074b60 100644 --- a/exercises/05factorial.py +++ b/exercises/05factorial.py @@ -9,3 +9,17 @@ # # > 120 # + + +print(range(1, 10)) + +def factorial(num): + + if num < 3: + return num + + return num * factorial(num - 1) + + return prod + +print(factorial(5)) \ No newline at end of file