From 85801f50b235e5c5dd23bdfb008337160041df69 Mon Sep 17 00:00:00 2001 From: tpressly Date: Tue, 18 Jun 2024 05:10:48 +0000 Subject: [PATCH 1/4] Finished Program --- src/02 Identify a Palindrome/pal_challenge.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/02 Identify a Palindrome/pal_challenge.py 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 From 81b756c1a3c91c0c4ef62e64e054722c027b509c Mon Sep 17 00:00:00 2001 From: tpressly Date: Tue, 18 Jun 2024 05:11:50 +0000 Subject: [PATCH 2/4] changed setting --- .vscode/settings.json | 1 - 1 file changed, 1 deletion(-) 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 From 4fe8a8cd3be37b4a2c7ba67f0b37e013cee47c4c Mon Sep 17 00:00:00 2001 From: tpressly Date: Wed, 19 Jun 2024 13:19:40 -0500 Subject: [PATCH 3/4] Create prime_challenge.py My solution to the prime challenge. --- src/01 Find Prime Factors/prime_challenge.py | 39 ++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/01 Find Prime Factors/prime_challenge.py 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)) From d34ef4425267ea20fcbb614aa96fa357e66492d3 Mon Sep 17 00:00:00 2001 From: tpressly Date: Wed, 19 Jun 2024 14:05:27 -0500 Subject: [PATCH 4/4] Create sortString_Challenge.py my solution to string sort challenge --- src/03 Sort a String/sortString_Challenge.py | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/03 Sort a String/sortString_Challenge.py 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'))