diff --git a/01-cconsonant-count.py b/01-cconsonant-count.py index 0a576e9..40051f2 100644 --- a/01-cconsonant-count.py +++ b/01-cconsonant-count.py @@ -11,4 +11,35 @@ Input: 'SpamAndEggs' Output: 8 -''' \ No newline at end of file +''' + +# 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')) \ No newline at end of file diff --git a/02-fibonacci.py b/02-fibonacci.py index c71242e..76337c1 100644 --- a/02-fibonacci.py +++ b/02-fibonacci.py @@ -17,4 +17,13 @@ input: 30 output: 832040 -''' \ No newline at end of file +''' + +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)) \ No newline at end of file diff --git a/03-reverse-string.py b/03-reverse-string.py index b9ce3e4..ce9020b 100644 --- a/03-reverse-string.py +++ b/03-reverse-string.py @@ -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")) \ No newline at end of file diff --git a/04-pretty-print.py b/04-pretty-print.py index 18c7f29..75425d9 100644 --- a/04-pretty-print.py +++ b/04-pretty-print.py @@ -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} \ No newline at end of file +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) \ No newline at end of file