diff --git a/.vscode/settings.json b/.vscode/settings.json index 2369810..ca20f95 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -17,7 +17,6 @@ "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 diff --git a/src/01 Find Prime Factors/prime_challenge.py b/src/01 Find Prime Factors/prime_challenge.py new file mode 100644 index 0000000..15f77de --- /dev/null +++ b/src/01 Find Prime Factors/prime_challenge.py @@ -0,0 +1,39 @@ +from math import sqrt as sqrt + +# challenge return all prime factors (including duplicates) as a list +# a*b*c*d*e = number +def get_prime_factors(bigNum): + if not isinstance(bigNum, int): return "Error" + if bigNum < 2: return "Error" + myList = list() + sqrtNum = int(sqrt(bigNum))+1 + keepLooping = True + while keepLooping: + factor = get_factor(bigNum, sqrtNum) + if factor is not None: + myList.append(factor) + bigNum = int (bigNum / factor) + if sqrtNum > 3: + keepLooping = True + else: + keepLooping = False + else: + keepLooping = False + + if bigNum > 1: myList.append(int(bigNum)) + return myList + +def get_factor(Num, sqrtNum): + factor = None + #print(Num, sqrtNum) + for i in range(2, sqrtNum, 1): + #print(i) + if ((int(Num) % i ) == 0) : + factor = i + break + else: + continue + return factor + + +print(get_prime_factors(630)) diff --git a/src/02 Identify a Palindrome/pal_challenge.py b/src/02 Identify a Palindrome/pal_challenge.py new file mode 100644 index 0000000..c809382 --- /dev/null +++ b/src/02 Identify a Palindrome/pal_challenge.py @@ -0,0 +1,24 @@ +# Python Code Challenge #2: Identify a Palindrome +# Your goal is to implement a function, +# `is_palindrome()`, that takes a text string +# as the input argument and returns a boolean +# indicating whether or not it's a palindrome. + +def is_palindrome(myString): + myString = cleanString(myString) + print(myString) + revString = myString[::-1] + result = False + if revString == myString: result = True + return result + +def cleanString(myString): + myString = myString.upper() + newString='' + for i in myString: + if ord(i) > 64 and ord(i) < 91: + newString = newString + i + return newString + + +print(is_palindrome("Go hang a salami - I'm a lasagna hog.")) \ No newline at end of file diff --git a/src/03 Sort a String/sortString_Challenge.py b/src/03 Sort a String/sortString_Challenge.py new file mode 100644 index 0000000..d15a2f4 --- /dev/null +++ b/src/03 Sort a String/sortString_Challenge.py @@ -0,0 +1,24 @@ + +# function to sort the words in a string and return the sorted string. +# ignore case when sorting + +def sort_words(myString): + myList = myString.split(' ') + # print(myList) + myList = sorted(myList, key=str.casefold) + # print(myList) + return (' '.join(myList)) + + +#def make_List(myString): +# myList = myString.split(' ') +# return myList + +#def list(myList): +# def __lt__(myList): +# ulist = list.lower() +# umyList = list.upper() +# return ulist < umyList + +print(sort_words('string of words')) +print(sort_words('banana ORANGE apple'))