diff --git a/.vscode/settings.json b/.vscode/settings.json index 2369810..0dde038 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -17,8 +17,25 @@ "files.autoSave": "afterDelay", "screencastMode.onlyKeyboardShortcuts": true, "terminal.integrated.fontSize": 18, - "workbench.activityBar.visible": true, "workbench.colorTheme": "Visual Studio Dark", "workbench.fontAliasing": "antialiased", - "workbench.statusBar.visible": true -} + "workbench.statusBar.visible": true, + "MicroPython.executeButton": [ + { + "text": "▶", + "tooltip": "Run", + "alignment": "left", + "command": "extension.executeFile", + "priority": 3.5 + } + ], + "MicroPython.syncButton": [ + { + "text": "$(sync)", + "tooltip": "sync", + "alignment": "left", + "command": "extension.execute", + "priority": 4 + } + ] +} \ No newline at end of file diff --git a/02/02_02/02_02b/main.py b/02/02_02/02_02b/main.py index 8aca3e1..76364f9 100644 --- a/02/02_02/02_02b/main.py +++ b/02/02_02/02_02b/main.py @@ -2,3 +2,14 @@ Problem Statement: Compute the average number of pets each student has in a given class. ''' +student_pet_cnt = [0,1,2,3,4,0,3,2,1,0,0,3,2,1,0,0,2] + +number_of_students = len(student_pet_cnt) + +print(number_of_students) + +sum = 0 +for count in student_pet_cnt: + sum = sum + count +print(sum) +print(sum/len(student_pet_cnt)) \ No newline at end of file diff --git a/02/02_05/02_05b/main.py b/02/02_05/02_05b/main.py index fbdc20f..a10a773 100644 --- a/02/02_05/02_05b/main.py +++ b/02/02_05/02_05b/main.py @@ -4,3 +4,4 @@ ["Katherine", "Lauren", "Mary", "Nathan", "Olive"], ["Chad", "April", "Matt", "Thomas", "Penny"] ] +print(seating_chart[2][1]) \ No newline at end of file diff --git a/02/02_09/02_09b/main.py b/02/02_09/02_09b/main.py index 7b9b5fa..4551836 100644 --- a/02/02_09/02_09b/main.py +++ b/02/02_09/02_09b/main.py @@ -1,4 +1,21 @@ def find_second_smallest(my_list): - return 0 + if len(my_list) <= 1: + return None + else: + smallest = float('inf') + second_smallest = float('inf') + + for item in my_list: + if item < smallest: + second_smallest = smallest + smallest = item + elif item < second_smallest: + second_smallest = item + return second_smallest + + + print(find_second_smallest([5, 8, 3, 2, 6])) +print(find_second_smallest([5])) +print(find_second_smallest([5, 3, 3, 2, 6])) \ No newline at end of file diff --git a/03/03_02/03_02b/main.py b/03/03_02/03_02b/main.py index 38e1a25..0598faf 100644 --- a/03/03_02/03_02b/main.py +++ b/03/03_02/03_02b/main.py @@ -1,2 +1,7 @@ # Key: State # Value: Capital +state = { + 'fl': 'tl', 'al':'tsk' +} + +print(state.keys()) \ No newline at end of file diff --git a/03/03_04/03_04b/main.py b/03/03_04/03_04b/main.py index b5a35fb..0322164 100644 --- a/03/03_04/03_04b/main.py +++ b/03/03_04/03_04b/main.py @@ -8,7 +8,13 @@ def update_preferences(user_pref): - return {} + new_user_prefs = {} + for key, value in user_pref.items(): + if value != None: + new_user_prefs[key] = value + + + return new_user_prefs print(update_preferences(user_preferences)) diff --git a/04/04_03/04_03b/main.py b/04/04_03/04_03b/main.py index afc5a1c..148ba30 100644 --- a/04/04_03/04_03b/main.py +++ b/04/04_03/04_03b/main.py @@ -1,2 +1,4 @@ set_A = {10, 20, 30, 40, 50} set_B = {30, 40, 50, 60, 70} + +print(set_A.union(set_B)) \ No newline at end of file diff --git a/04/04_05/04_05b/main.py b/04/04_05/04_05b/main.py index 5264285..8260470 100644 --- a/04/04_05/04_05b/main.py +++ b/04/04_05/04_05b/main.py @@ -1,6 +1,8 @@ def has_unique_characters(data): - return False - + data_set = set(data) + return len(data_set) == len(data) + + print(has_unique_characters('sample')) print(has_unique_characters('hello world')) print(has_unique_characters('linkedin')) diff --git a/05/05_04/05_04b/main.py b/05/05_04/05_04b/main.py index e69de29..f191dab 100644 --- a/05/05_04/05_04b/main.py +++ b/05/05_04/05_04b/main.py @@ -0,0 +1,16 @@ +from collections import deque +''' 0001 + 0010 + 0011 + 0100 + 0101 + 1101 + 0111 + 1000 + 1001 +''' + +def print_bin_num(a): + if a <= 0: + return None + \ No newline at end of file diff --git a/06/06_05/06_05b/main.py b/06/06_05/06_05b/main.py index e69de29..d59b503 100644 --- a/06/06_05/06_05b/main.py +++ b/06/06_05/06_05b/main.py @@ -0,0 +1,21 @@ +from collections import deque + +def matching_para(text): + stack = deque() + for char in text: + if char == '(': + stack.append(char) + + elif char == ')': + if not stack: + return False + stack.pop() + + + + return len(stack) == 0 + + + + +print(matching_para(')(hi )there)('))