All chart.js graded assignment limits, continuity, differentiability, and derivatives mathematics mathematics graded assignment mathematics practice assignment oope exam polynomial practice assignment pyq python graded assignment quadratic equation quiz 2 relations and sets statistics graded assignment sum of squared errors week-6-logarithms week-7-sequence-and-limits

Profile SVG
Python OOPE Exam 2024 Sep Oppe 1 Set 1

🧮 Function: is_positive_odd_or_negative_even Let’s build a Python function that checks if a number is either a positive odd or a negative even. 🎯 🚩 Function Definition def is_positive_odd_or_negative_even(n): # Check for positive odd OR negative even return (n > 0 and n % 2 == 1) or (n < 0 and n % 2 == 0) 📝 Step-by-Step Explanation Positive Odd Number: Condition: n > 0 and n % 2 == 1 Checks if the number is positive AND odd. Negative Even Number: Condition: n < 0 and n % 2 == 0 Checks if the number is negative AND even. Logical OR: The function returns True if any one of the above conditions is met. 🧪 Practice Questions Practice 1 print(is_positive_odd_or_negative_even(7)) # _______ 7 is positive and odd. Output: True Practice 2 print(is_positive_odd_or_negative_even(-4)) # _______ -4 is negative and even. Output: True Practice 3 print(is_positive_odd_or_negative_even(-3)) # _______ -3 is negative and odd. Output: False Practice 4 print(is_positive_odd_or_negative_even(8)) # _______ 8 is positive and even. Output: False Practice 5 print(is_positive_odd_or_negative_even(0)) # _______ 0 is neither positive nor negative (and it’s even). Output: False ✨ Key Points Odd number: Remainder when divided by 2 is 1 (n % 2 == 1). Even number: Remainder when divided by 2 is 0 (n % 2 == 0). Positive Odd or Negative Even: Only one of these is needed for True. Zero case: 0 is not positive or negative, so always returns False. Happy Coding! 🚀

Profile SVG
Python OOPE Exam 2024 Sep Oppe 1 Set 1

📝 Function: within_and_has_double_quotes Let’s build a Python function to check if a string: Starts and ends with double quotes (") Has at least one double quote somewhere inside (not including the first and last characters) 🧑‍💻 Function Implementation def within_and_has_double_quotes(s): # Check if string has at least 2 characters and starts/ends with a double quote if len(s) < 2 or s[0] != '"' or s[-1] != '"': return False # Check for another double quote in the interior (exclude first/last char) return '"' in s[1:-1] 🔍 Step-by-Step Explanation Check the boundary quotes: The string must be at least 2 characters. The first character is " and the last character is ". Check for an internal quote: Use s[1:-1] to get the inner part of the string (excluding first and last characters). Test if " exists in this interior slice. 🧪 Practice Questions Practice 1 print(within_and_has_double_quotes('"hello"')) # _______ Interior: hello (no quotes) Output: False Practice 2 print(within_and_has_double_quotes('"he"llo"')) # _______ Interior: he"llo Yes, has an interior double quote! Output: True Practice 3 print(within_and_has_double_quotes('""')) # _______ Interior: empty string "" Output: False Practice 4 print(within_and_has_double_quotes('"a"b"c"')) # _______ Interior: a"b"c Yes, contains double quotes inside! Output: True Practice 5 print(within_and_has_double_quotes('"no inner quote')) # _______ No ending double quote. Output: False ✅ Key Points Checks boundaries (" at both ends) Looks inside (middle of string) for at least one more double quote Returns True only if both conditions are met Happy Coding! 🚀

Profile SVG
Python OOPE Exam 2024 Sep Oppe 1 Set 1

📝 Function: Replace Middle Element with n Copies Let’s build a helpful Python function that replaces the middle element of a tuple with n copies of itself! 🧑‍💻✨ 🚩 Function Definition def replace_middle_with_n_copies(t, n): # Find the middle index mid = len(t) // 2 # Create a tuple with 'n' copies of the middle element middle_replacement = (t[mid],) * n # Build the new tuple: before + replacement + after return t[:mid] + middle_replacement + t[mid+1:] 🔍 Step-by-Step Explanation Find the Middle Index Since the tuple has odd length, the middle index is len(t) // 2. Create Replacement (t[mid],) * n makes n copies of the middle element as a tuple. Assemble the Result Use slicing: t[:mid] (elements before the middle), middle_replacement, and t[mid+1:] (elements after the middle). 🤔 Practice Questions Practice 1 t = (1, 2, 3, 4, 5) n = 3 print(replace_middle_with_n_copies(t, n)) # What do you expect? Middle element: 3 Should be replaced by (3, 3, 3) Result: (1, 2, 3, 3, 3, 4, 5) Practice 2 t = ('a', 'b', 'c') n = 2 print(replace_middle_with_n_copies(t, n)) Middle element: 'b' Result: ('a', 'b', 'b', 'c') Practice 3 t = (10,) n = 4 print(replace_middle_with_n_copies(t, n)) Single element tuple: replace with 4 copies of itself. Result: (10, 10, 10, 10) ✨ Tips Tuples are immutable: You can’t change them; instead, create and return a new tuple. Odd length guaranteed: No need to check for even-length inputs. Works for any tuple type: numbers, strings, or mixed! Happy Python-ing! 🐍🚀

Profile SVG
Python OOPE Exam 2024 Sep Oppe 1 Set 1

🏃‍♂️ Matrix Walk Function Let’s design a Python function that follows three special matrix paths — “L”, “Z”, and “O” shapes — and collects the matrix elements accordingly! 🚀 🧑‍💻 Function Definition def matrix_walk(matrix, path): n = len(matrix) result = [] if path == "L": # Down the first column for i in range(n): result.append(matrix[i][0]) # Across the bottom row, excluding first element for j in range(1, n): result.append(matrix[n-1][j]) return result elif path == "Z": # Top row for j in range(n): result.append(matrix[0][j]) # Diagonal except first and last row for i in range(1, n-1): result.append(matrix[i][n-i-1]) # Bottom row for j in range(n): result.append(matrix[n-1][j]) return result elif path == "O": # Top row for j in range(n): result.append(matrix[0][j]) # Right column (excluding top and bottom) for i in range(1, n-1): result.append(matrix[i][n-1]) # Bottom row (reverse, excluding last element) for j in range(n-1, -1, -1): result.append(matrix[n-1][j]) # Left column (reverse, excluding top and bottom) for i in range(n-2, 0, -1): result.append(matrix[i][0]) return result else: return [] 🔍 Step-by-Step Explanation 1. L-Shape (“L”) Walk down the first column (leftmost). Then walk right along the bottom row (skipping the already-added first element). 2. Z-Shape (“Z”) Walk across the top row (left to right). Walk diagonally from the top-right to bottom-left, excluding corners. Walk across the bottom row (left to right). 3. O-Shape (“O”) Walk around the outside (clockwise): Top row (left to right), Right column (top to bottom, skipping corners), Bottom row (right to left), Left column (bottom to top, skipping corners). 🧪 Practice Questions with Solutions Example Matrix matrix = [ [1, 2, 3], [4, 5, 6], [7, 8, 9] ] Practice 1: L-Shape print(matrix_walk(matrix, "L")) # Output: [1, 4, 7, 8, 9] Practice 2: Z-Shape print(matrix_walk(matrix, "Z")) # Output: [1, 2, 3, 5, 7, 8, 9] Practice 3: O-Shape print(matrix_walk(matrix, "O")) # Output: [1, 2, 3, 6, 9, 8, 7, 4] ✨ Key Points The function traverses only as per the specified path — “L”, “Z”, or “O”. For unknown paths, returns an empty list. Works for any square matrix of size 1 or more. Happy Matrix Walking! 🟦🟩🟨🟥

Profile SVG
Python OOPE Exam 2024 Sep Oppe 1 Set 1

🚀 Function: increment_value_with_max_limit Here’s a function to increment the value for a given key in a dictionary, making sure it never exceeds a specified maximum limit! def increment_value_with_max_limit(d, key, inc, limit): """ Increment the value of d[key] by inc, but do not let it exceed limit. Args: d (dict): Dictionary with integer values. key: Key whose value you want to increment. inc (int): The increment value. limit (int): The maximum allowed value. Returns: None: The dictionary is modified in-place. Example: d = {'a': 5} increment_value_with_max_limit(d, 'a', 10, 12) # Now d['a'] == 12 """ if key in d: d[key] = min(d[key] + inc, limit) ✨ Step-by-Step Explanation Check Key Exists: Make sure the key is present in the dictionary. Increment and Cap: Add the inc value to the current value for the key. Use min(new_value, limit) to cap the result at limit if it would go over. Update In Place: The original dictionary is modified directly. No return value necessary! 📝 Practice Questions If d = {'x': 7}, what does increment_value_with_max_limit(d, 'x', 4, 10) do? What happens for d = {'b': 2}, increment_value_with_max_limit(d, 'b', 5, 5)? Try d = {'score': 20}, increment_value_with_max_limit(d, 'score', 3, 22) ✅ Solutions The value becomes min(7+4, 10) = 10. So, d['x'] will be 10. The value becomes min(2+5, 5) = 5. So, d['b'] will be 5. The value becomes min(20+3, 22) = 22. So, d['score'] will be 22. 💡 Now you can safely increment dictionary values without ever exceeding the maximum you set!

Profile SVG
Python OOPE Exam 2024 Sep Oppe 1 Set 1

🔎 Function: Find Last Word Starting with Uppercase Here’s how you can implement the last_word_starts_with_upper_case function to find the last word in a sentence that starts with an uppercase letter. If no such word exists, it returns None. 🛠️ Function Definition def last_word_starts_with_upper_case(sentence: str): """ Find the last word in a sentence that starts with an uppercase letter. Args: sentence (str): The input sentence. Returns: str or None: The last word starting with an uppercase letter, or None if no such word exists. """ result = None for word in sentence.split(): if word and word[0].isupper(): result = word return result ✨ Step-by-Step Explanation Step 1: Split the sentence into individual words using split(). Step 2: Loop through each word: If the word starts with an uppercase letter (word.isupper()), save it as the current result. Step 3: After checking all words, return the last word found that met the criteria, or None if none did. 🚦 Example Usage print(last_word_starts_with_upper_case("This is a Test sentence")) # Output: "Test" print(last_word_starts_with_upper_case("no uppercase words here")) # Output: None 📝 Practice Questions What will last_word_starts_with_upper_case("Alice and Bob went to Paris") return? Try last_word_starts_with_upper_case("all lowercase words"). What is the result of last_word_starts_with_upper_case("Python Is Easy To Learn")? ✅ Solutions "Paris" None "Learn" With this function, you can quickly scan sentences for the last word that begins with a capital letter. Perfect for text analysis and simple parsing tasks! 🐍💡

Profile SVG
Python OOPE Exam 2024 Sep Oppe 1 Set 1

📝 Filter Words by Custom Criteria Below is the requested function to filter a list of words based on one of four criteria: continuous, vowel_rich, consonant_rich, or sorted. Words are checked case-insensitively, and helper functions are included for each criteria. def filter_words(words, criteria): """ Filters a list of words based on the given criteria. Args: words (list of str): Input list of words. criteria (str): One of 'continuous', 'vowel_rich', 'consonant_rich', 'sorted'. Returns: list or None: Filtered list based on criteria, or None if invalid. Criteria: • 'continuous': words ending with 'ing' (case-insensitive) • 'vowel_rich': words with more than 5 vowels • 'consonant_rich': words with more than 5 consonants • 'sorted': words whose letters are in ascending order (case-insensitive) """ def is_continuous(word): return word.lower().endswith('ing') def count_vowels(word): return sum(1 for ch in word.lower() if ch in "aeiou") def count_consonants(word): return sum(1 for ch in word.lower() if ch.isalpha() and ch not in "aeiou") def is_sorted(word): letters = [ch.lower() for ch in word if ch.isalpha()] return letters == sorted(letters) if criteria == 'continuous': return [w for w in words if is_continuous(w)] elif criteria == 'vowel_rich': return [w for w in words if count_vowels(w) > 5] elif criteria == 'consonant_rich': return [w for w in words if count_consonants(w) > 5] elif criteria == 'sorted': return [w for w in words if is_sorted(w)] else: return None ✨ Step-by-Step Explanation Helper Functions: is_continuous: Checks if the word ends with “ing” (case-insensitive). count_vowels: Counts vowels (a, e, i, o, u). count_consonants: Counts consonants (alphabetic letters that are not vowels). is_sorted: Checks if the letters of the word are in ascending order. Criteria Check: The function checks the criteria argument and applies the relevant helper. If an unknown criteria is given, returns None. 🧪 Practice Questions Try calling the function on the following list: