diff --git a/.vscode/settings.json b/.vscode/settings.json index 2369810..0aeb945 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -17,8 +17,11 @@ "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, + "githubPullRequests.ignoredPullRequestBranches": [ + "main" + ], + "python.REPL.enableREPLSmartSend": false +} \ No newline at end of file diff --git a/src/01 Find Prime Factors/findingprimefactors.py b/src/01 Find Prime Factors/findingprimefactors.py new file mode 100644 index 0000000..7afe94a --- /dev/null +++ b/src/01 Find Prime Factors/findingprimefactors.py @@ -0,0 +1,17 @@ +def get_prime_factors(number): + factors=[] + factor=2 + while factor<=number: + if (number%factor==0): + factors.append(factor) + number=number/factor + else: + factor=factor+1 + return factors + + + +print(get_prime_factors(21)) +print(get_prime_factors(2300)) +print(get_prime_factors(347)) +print(get_prime_factors(0)) \ No newline at end of file diff --git a/src/02 Identify a Palindrome/identifyingpalindrome.py b/src/02 Identify a Palindrome/identifyingpalindrome.py new file mode 100644 index 0000000..2716170 --- /dev/null +++ b/src/02 Identify a Palindrome/identifyingpalindrome.py @@ -0,0 +1,25 @@ +def palindrome(string): + text = "" + reversed_text = "" + + for char in string: + if char!=" ": + text+=char.lower() + + + + for char in reversed(string): + if char!=" ": + reversed_text+=char.lower() + + + return reversed_text==text + + + +print(palindrome("No lemon no melon")) +print(palindrome("race car")) +print(palindrome("hello")) + + + diff --git a/src/03 Sort a String/mysolution.py b/src/03 Sort a String/mysolution.py new file mode 100644 index 0000000..7c0b0d2 --- /dev/null +++ b/src/03 Sort a String/mysolution.py @@ -0,0 +1,9 @@ +def sort_words(s): + words = s.split() + words.sort(key=str.lower) + return ' '.join(words) + + +result = sort_words('banana ORANGE apple') +print(result) + diff --git a/src/04 Find All List Items/Find_a_list_item.py b/src/04 Find All List Items/Find_a_list_item.py new file mode 100644 index 0000000..67dc9d7 --- /dev/null +++ b/src/04 Find All List Items/Find_a_list_item.py @@ -0,0 +1,16 @@ +def index_all(obj, item): + result = [] + + def search(sub_obj, path): + if isinstance(sub_obj, list): + for i, element in enumerate(sub_obj): + search(element, path + [i]) + else: + if sub_obj == item: + result.append(path) + + search(obj, []) + return result +example = [[[1, 2, 3], 2, [1, 3]], [1, 2, 3]] + +print(index_all(example, 1)) \ No newline at end of file