diff --git a/solutions/python/bob/1/bob.py b/solutions/python/bob/1/bob.py new file mode 100644 index 0000000..973229d --- /dev/null +++ b/solutions/python/bob/1/bob.py @@ -0,0 +1,24 @@ +def response(hey_bob): + # Fix the Indentation for all lines below! + trimmed_input = hey_bob.strip() + + # Yelling a Question (Most Specific) + if trimmed_input.endswith('?') and trimmed_input.isupper(): + return "Calm down, I know what I'm doing!" + + # Yelling (Next Specific) + # Be careful not to count empty strings or questions as yelling! + elif trimmed_input.isupper(): + return "Whoa, chill out!" + + # Question (Next Specific) + elif trimmed_input.endswith('?'): + return "Sure." + + # Silence + elif trimmed_input == '': + return "Fine. Be that way!" + + # Anything Else + else: + return "Whatever." diff --git a/solutions/python/darts/1/darts.py b/solutions/python/darts/1/darts.py new file mode 100644 index 0000000..5b3d771 --- /dev/null +++ b/solutions/python/darts/1/darts.py @@ -0,0 +1,26 @@ +def score(x, y): + pass + distance_squared = x**2 + y**2 + + # Define the squared radii for comparison + RADIUS_1_SQUARED = 1**2 # 1 (Inner Circle) + RADIUS_5_SQUARED = 5**2 # 25 (Middle Circle) + RADIUS_10_SQUARED = 10**2 # 100 (Outer Circle / Max Target) + + # 2. Use conditional logic, checking the smallest (highest score) circle first. + + if distance_squared <= RADIUS_1_SQUARED: + # Distance <= 1: Inner Circle + return 10 + + elif distance_squared <= RADIUS_5_SQUARED: + # 1 < Distance <= 5: Middle Circle + return 5 + + elif distance_squared <= RADIUS_10_SQUARED: + # 5 < Distance <= 10: Outer Circle + return 1 + + else: + # Distance > 10: Outside the target + return 0 \ No newline at end of file diff --git a/solutions/python/little-sisters-vocab/1/strings.py b/solutions/python/little-sisters-vocab/1/strings.py new file mode 100644 index 0000000..5014fe1 --- /dev/null +++ b/solutions/python/little-sisters-vocab/1/strings.py @@ -0,0 +1,75 @@ +"""Functions for creating, transforming, and adding prefixes to strings.""" + + +def add_prefix_un(word): + """Take the given word and add the 'un' prefix. + + :param word: str - containing the root word. + :return: str - of root word prepended with 'un'. + """ + return "un" + word + + +def make_word_groups(vocab_words): + """Transform a list containing a prefix and words into a string with the prefix followed by the words with prefix prepended. + + :param vocab_words: list - of vocabulary words with prefix in first index. + :return: str - of prefix followed by vocabulary words with + prefix applied. + + This function takes a `vocab_words` list and returns a string + with the prefix and the words with prefix applied, separated + by ' :: '. + + For example: list('en', 'close', 'joy', 'lighten'), + produces the following string: 'en :: enclose :: enjoy :: enlighten'. + """ + prefix = vocab_words[0] + words = vocab_words[1:] + + # Use a list comprehension to apply the prefix to every word + prefixed_words = [prefix + word for word in words] + + # Combine the original prefix and the new prefixed words, then join with ' :: ' + return ' :: '.join([prefix] + prefixed_words) + + +def remove_suffix_ness(word): + """Remove the suffix from the word while keeping spelling in mind. + + :param word: str - of word to remove suffix from. + :return: str - of word with suffix removed & spelling adjusted. + + For example: "heaviness" becomes "heavy", but "sadness" becomes "sad". + """ + if word.endswith("ness"): + # remove 'ness' + root = word[:-4] + + # spelling rule: if word ends with 'i', change to 'y' + if root.endswith("i"): + root = root[:-1] + "y" + + return root + + return word + +def adjective_to_verb(sentence, index): + """Change the adjective within the sentence to a verb. + + :param sentence: str - that uses the word in sentence. + :param index: int - index of the word to remove and transform. + :return: str - word that changes the extracted adjective to a verb. + + For example, ("It got dark as the sun set.", 2) becomes "darken". + """ + selected_word = sentence.split()[index] + + # 2. Clean the word (remove any trailing punctuation) + cleaned_word = selected_word.rstrip('.,!?"') + + # 3. Append the suffix 'en' + suffix = "en" + + # 4. Return the new verb + return cleaned_word + suffix diff --git a/solutions/python/little-sisters-vocab/2/strings.py b/solutions/python/little-sisters-vocab/2/strings.py new file mode 100644 index 0000000..91cc43d --- /dev/null +++ b/solutions/python/little-sisters-vocab/2/strings.py @@ -0,0 +1,75 @@ +"""Functions for creating, transforming, and adding prefixes to strings.""" + + +def add_prefix_un(word): + """Take the given word and add the 'un' prefix. + + :param word: str - containing the root word. + :return: str - of root word prepended with 'un'. + """ + return "un" + word + + +def make_word_groups(vocab_words): + """Transform a list containing a prefix and words into a string with the prefix followed by the words with prefix prepended. + + :param vocab_words: list - of vocabulary words with prefix in first index. + :return: str - of prefix followed by vocabulary words with + prefix applied. + + This function takes a `vocab_words` list and returns a string + with the prefix and the words with prefix applied, separated + by ' :: '. + + For example: list('en', 'close', 'joy', 'lighten'), + produces the following string: 'en :: enclose :: enjoy :: enlighten'. + """ + prefix = vocab_words[0] + words = vocab_words[1:] + + # Use a list comprehension to apply the prefix to every word + prefixed_words = [prefix + word for word in words] + + # Combine the original prefix and the new prefixed words, then join with ' :: ' + return " :: ".join([prefix] + prefixed_words) + + +def remove_suffix_ness(word): + """Remove the suffix from the word while keeping spelling in mind. + + :param word: str - of word to remove suffix from. + :return: str - of word with suffix removed & spelling adjusted. + + For example: "heaviness" becomes "heavy", but "sadness" becomes "sad". + """ + if word.endswith("ness"): + # remove 'ness' + root = word[:-4] + + # spelling rule: if word ends with 'i', change to 'y' + if root.endswith("i"): + root = root[:-1] + "y" + + return root + + return word + +def adjective_to_verb(sentence, index): + """Change the adjective within the sentence to a verb. + + :param sentence: str - that uses the word in sentence. + :param index: int - index of the word to remove and transform. + :return: str - word that changes the extracted adjective to a verb. + + For example, ("It got dark as the sun set.", 2) becomes "darken". + """ + selected_word = sentence.split()[index] + + # 2. Clean the word (remove any trailing punctuation) + cleaned_word = selected_word.rstrip('.,!?"') + + # 3. Append the suffix 'en' + suffix = "en" + + # 4. Return the new verb + return cleaned_word + suffix diff --git a/solutions/python/raindrops/1/raindrops.py b/solutions/python/raindrops/1/raindrops.py new file mode 100644 index 0000000..3783e0a --- /dev/null +++ b/solutions/python/raindrops/1/raindrops.py @@ -0,0 +1,28 @@ +def convert(number): + """ + Converts a number into its corresponding raindrop sounds (Pling, Plang, Plong) + based on divisibility by 3, 5, and 7. + """ + + # Start with an empty string to accumulate the sounds. + raindrops = "" + + # Check for divisibility by 3. + # We use independent 'if' statements so we can add multiple sounds. + if number % 3 == 0: + raindrops += "Pling" + + # Check for divisibility by 5. + if number % 5 == 0: + raindrops += "Plang" + + # Check for divisibility by 7. + if number % 7 == 0: + raindrops += "Plong" + + # If the string is empty, it means the number was not divisible by 3, 5, or 7. + # In that case, we return the original number as a string. + if not raindrops: + return str(number) + else: + return raindrops \ No newline at end of file