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
33 changes: 32 additions & 1 deletion 01-cconsonant-count.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,35 @@

Input: 'SpamAndEggs'
Output: 8
'''
'''

# def count_check(string):
# vowels = ["a", "e", "i", "o", "u"]

# if string == "":
# return 0
# if


def const_count(str):
vowel = 'aeiouAEIOU'
if str == '':
return 0
if str[0].casefold() not in vowel:
return 1 + const_count(str[1:])
else:
return const_count(str[1:])

print(const_count('SpamAndEggs'))

# def consonant_count(str):
# cons = 0
# vowels = ['a', 'e', 'i', 'o', 'u']
# for char in str:
# if(char not in vowels):
# cons += 1
# else:
# cons = cons
# return cons

# print(consonant_count('airplane'))
11 changes: 10 additions & 1 deletion 02-fibonacci.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,13 @@

input: 30
output: 832040
'''
'''

def fibbonacci(n):
#base case is n == 1 or2
if n == 1 or n == 2:
return 1
else:
return fibbonacci(n - 1) + fibbonacci(n - 2)

print(fibbonacci(30))
9 changes: 9 additions & 0 deletions 03-reverse-string.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,12 @@
input: "abcdefghijklmnopqrstuvwxyz"
output: "zyxwvutsrqponmlkjihgfedcba"
'''

def reverse(string):
if len(string) <= 1:
return string
else:
print(string)
return reverse(string[1:]) + string[0]

print(reverse("hello world"))
24 changes: 23 additions & 1 deletion 04-pretty-print.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,26 @@
# use these for testing
o1 = {"a": 1, "b": 2}
o2 = {"a": 1, "b": 2, "c": {"name": "Bruce Wayne", "occupation": "Hero"}, "d": 4}
o3 = {"a": 1, "b": 2, "c": {"name": "Bruce Wayne", "occupation": "Hero", "friends": {"spiderman": {"name": "Peter Parker"}, "superman": {"name": "Clark Kent"}}}, "d": 4}
o3 = {"a": 1, "b": 2, "c": {"name": "Bruce Wayne", "occupation": "Hero", "friends": {"spiderman": {"name": "Peter Parker"}, "superman": {"name": "Clark Kent"}}}, "d": 4}


# def pretty_print(dictionary, indent):
# for key, value in dictionary.items():
# if type(dictionary[key]) == type({}):
# print(f"{indent}{key}:{f"pretty_print(dictionary[key], + " ")}")
# else:
# print(f"{indent}{key}: {dictionary[key]}")

# pretty_print(o2, "")

def pretty_print(dictionary, indentation = ""):
#iterate over whole dictionary
for key in dictionary:
value = dictionary[key]
if indentation(value, dict):
print(f"{indentation}{key}:")
pretty_print(value, indentation + " ")
else:
print(f"{indentation}{key}:{value}")

pretty_print(o3)