Skip to content
Open
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions exercises/01loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
12 changes: 12 additions & 0 deletions exercises/02letter_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
7 changes: 7 additions & 0 deletions exercises/03print_contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 8 additions & 0 deletions exercises/04multiply_by.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
14 changes: 14 additions & 0 deletions exercises/05factorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))