source
stringclasses
6 values
id
int64
0
111k
instruction
stringlengths
167
4.39k
response
stringlengths
244
6.1k
python_sharegpt_23k
2,898
Write a Python function to validate a message based on the following criteria: 1. The message should not exceed 100 characters. 2. The message should only contain alphabetic characters (ignore any non-alphabetic characters). 3. The message must contain at least one uppercase letter and one lowercase letter. The functi...
Here is the Python code to solve the given problem in the markdown block: ```python import re def validate_message(message: str) -> str: """ Validates the message based on the following criteria: 1. The message should not exceed 100 characters. 2. The message should only contain alphabetic characters (...
python_sharegpt_23k
2,899
Write a Python function to calculate the cube of any number using only addition and multiplication operations. The function should handle both positive and negative numbers. The code should start with: ```python def cube_using_addition_and_multiplication(number: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def cube_using_addition_and_multiplication(number: int) -> int: """ Calculate the cube of a given number using only addition and multiplication operations. Args: number (int): The number to calculate the cube of. ...
python_sharegpt_23k
2,903
Write a Python function to remove duplicate elements from a given list while maintaining the order of the elements. The list can contain both positive and negative integers. The solution should have a time complexity of O(n) and should not use any built-in functions or libraries for removing duplicates. Additionally, y...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_duplicates(lst: List[int]) -> List[int]: """ Removes duplicate elements from a list while maintaining the order of the elements. Args: lst (List[int]): The list of integers from w...
python_sharegpt_23k
2,911
Write a Python function that takes two arguments, checks if they are positive integers, and returns the product of the two numbers. If the arguments are not positive integers, raise a `ValueError` with the message "Both arguments must be positive integers." The code should start with: ```python def multiply_positive_i...
Here is the Python code to solve the given problem in the markdown block: ```python def multiply_positive_integers(num1: int, num2: int) -> int: """ Multiplies two positive integers and returns the result. Args: num1 (int): The first positive integer. num2 (int): The second positive integer...
python_sharegpt_23k
2,917
Write a Python function to determine if a given positive integer is a prime palindrome number. A prime palindrome number is a number that is both prime and a palindrome. The function should return `True` if the number is a prime palindrome, and `False` otherwise. The code should start with: ```python def is_prime_palin...
Here is the Python code to solve the given problem in the markdown block: ```python import math def is_prime_palindrome(n: int) -> bool: """ Determine if a given positive integer is a prime palindrome number. Args: n (int): The positive integer to check. Returns: bool: True if the num...
python_sharegpt_23k
2,922
Write a Python function to update the values of a given dictionary by squaring each value. Additionally, the keys in the updated dictionary should be sorted in descending order based on their squared values. The function should start with: ```python from typing import Dict def update_and_sort_dict(my_dict: Dict[str, i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def update_and_sort_dict(my_dict: Dict[str, int]) -> Dict[str, int]: """ Updates the values of the given dictionary by squaring each value and sorts the keys in descending order based on their squared va...
python_sharegpt_23k
2,923
Write a Python function to calculate the sum of all prime numbers in a given list. The list may contain up to 1000 elements, and you are not allowed to use any built-in functions or libraries to check for prime numbers. The function should start with: ```python from typing import List def sum_of_primes(numbers: List[i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_prime(num: int) -> bool: """ Check if a number is prime. Args: num (int): The number to check for primality. Returns: bool: True if the number is prime, False otherwise. ...
python_sharegpt_23k
2,924
Write a Python function to find the common elements between two lists of integers and return them as a new list. The common elements should be unique and sorted in descending order. The function should handle lists with duplicate elements and return the correct result. The code should start with: ```python from typing...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_common_elements(list1: List[int], list2: List[int]) -> List[int]: """ Find the common elements between two lists of integers and return them as a new list. The common elements should be uniq...
python_sharegpt_23k
2,927
Write a Python function to update a nested dictionary by assigning a value to the innermost key specified by a list of keys. If any key in the hierarchy does not exist, the function should create the necessary key-value pairs to match the hierarchy and assign the value to the innermost key. The function should return t...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Any, Dict, List def update_nested_dict(nested_dict: Dict[str, Any], keys: List[str], value: Any) -> Dict[str, Any]: """ Updates a nested dictionary by assigning a value to the innermost key specified by a lis...
python_sharegpt_23k
2,940
Write a Python function to calculate the sum of all numbers in a given list that are divisible by both 3 and 5. The function should handle the case when the input list is empty or when there are no numbers that satisfy the condition, returning 0 in both cases. The implementation should not use any built-in functions or...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sum_divisible_by_three_and_five(numbers: List[int]) -> int: """ Calculate the sum of all numbers in the given list that are divisible by both 3 and 5. Args: numbers (List[int]): The list...
python_sharegpt_23k
2,949
Write a Python function to reverse a string without using the built-in `reverse` method or any additional variables or data structures. The function should reverse the characters of the original string in place and handle strings with special characters, whitespace, and Unicode characters correctly. The time complexity...
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string_in_place(string: str) -> str: """ Reverses a string in place without using the built-in 'reverse' method or any additional variables or data structures. Handles strings with special characters, whitespace,...
python_sharegpt_23k
2,966
Write a Python function to reduce a 3-dimensional numpy array of shape (n, m, k) to a 2-dimensional numpy array of shape (n*m, k), ensuring that the resulting array contains all the elements from the original array. Additionally, the resulting array should be sorted in ascending order based on the sum of the values in ...
Here is the Python code to solve the given problem in the markdown block: ```python import numpy as np def reduce_and_sort_array(arr: np.ndarray) -> np.ndarray: """ Reduce a 3-dimensional numpy array of shape (n, m, k) to a 2-dimensional numpy array of shape (n*m, k), and sort the resulting array based on ...
python_sharegpt_23k
2,967
Write a Python function to find and return the titles of the top 10 movies with the highest ratings from a given list of movie dictionaries. The movies should be sorted in descending order based on their ratings. If two movies have the same rating, prioritize the movie with the lower alphabetical title. The code shoul...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def get_top_10_movies(movies: List[Dict[str, any]]) -> List[str]: """ Returns the titles of the top 10 movies with the highest ratings from a given list of movie dictionaries. The movies are so...
python_sharegpt_23k
2,973
Write a Python function to find the length of the longest substring containing no repeated characters in a given string. The substring must be contiguous and the characters must appear in the same order as in the original string. The function should be efficient with a time complexity of O(n), where n is the length of ...
Here is the Python code to solve the given problem in the markdown block: ```python def longest_substring_length(s: str) -> int: """ Find the length of the longest substring with no repeated characters in the given string. Args: s (str): The input string to analyze. Returns: int: The l...
python_sharegpt_23k
2,979
Write a Python function to calculate the sum of the first n prime numbers. The function should take an integer `n` as input and return the sum of the first `n` prime numbers. The code should start with: ```python def sum_of_first_n_primes(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_first_n_primes(n: int) -> int: """ Calculate the sum of the first n prime numbers. Args: n (int): The number of prime numbers to sum. Returns: int: The sum of the first n prime numbers. "...
python_sharegpt_23k
2,987
Write a Python function named `split_reverse_sentence` that takes a sentence as a string and returns the words in reverse order. The function should use regular expressions to split the sentence into words and should not use any built-in string or array manipulation functions, such as `split()`, `reverse()`, or indexin...
Here is the Python code to solve the given problem in the markdown block: ```python import re def split_reverse_sentence(sentence: str) -> list: """ Splits a sentence into words using regular expressions and returns the words in reverse order. Args: sentence (str): The input sentence to be process...
python_sharegpt_23k
2,989
Write a Python function that processes a given array of integers by removing negative numbers, sorting the resulting array in ascending order, and removing any duplicates. Additionally, the function should calculate the sum of all the positive integers in the resulting array. The function should have a time complexity ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def process_array(arr: List[int]) -> Tuple[List[int], int]: """ Processes the given array of integers by removing negative numbers, sorting the resulting array in ascending order, removing any...
python_sharegpt_23k
2,990
Write a Python function to transpose a given square matrix. The matrix will always be square, meaning that the number of rows will always be equal to the number of columns. The size of the matrix will not exceed 100. Each element in the matrix will be an integer in the range of -100 to 100. The code should start with:...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def transpose_square_matrix(matrix: List[List[int]]) -> List[List[int]]: """ Transposes a given square matrix. Args: matrix (List[List[int]]): A square matrix represented as a list of lists ...
python_sharegpt_23k
2,992
Write a Python function to classify and label the outputs as either 0 or 1 using a logistic regression model. The logistic regression model is represented by the equation: \[ y = \frac{1}{1 + e^{-z}} \] where \( z \) is a linear combination of the input features and their corresponding weights. The weights are obtain...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import math def classify_logistic_regression(inputs: List[List[float]], weights: List[float]) -> List[int]: """ Classify and label the outputs as either 0 or 1 using a logistic regression model. Arg...
python_sharegpt_23k
2,996
Write a Python function to calculate the sum of squares of the first n natural numbers efficiently. The function should handle negative values for n by returning an error message and ensure that the final result is within the range of a 64-bit signed integer. The code should start with: ```python def sum_of_squares(n: ...
Here is the Python code to solve the given problem in the markdown block: ```python def sum_of_squares(n: int) -> int: """ Calculate the sum of squares of the first n natural numbers. Args: n (int): The number of natural numbers to sum the squares of. Returns: int: The sum of squares o...
python_sharegpt_23k
3,001
Write a Python function to process a given string and return a list of unique words in alphabetical order. The function should ignore punctuation marks and consider words with different capitalizations as the same word. The function should achieve this in a single pass over the input string and should not use any built...
Here is the Python code to solve the given problem in the markdown block: ```python def string_formatter(s: str) -> list: """ Processes a given string to return a list of unique words in alphabetical order. Ignores punctuation marks and considers words with different capitalizations as the same word. A...
python_sharegpt_23k
3,009
Write a Python function to sort a list of integers in ascending order using a divide and conquer approach with a time complexity of O(n log n). The algorithm should not use any built-in sorting functions or libraries. The sorted list should be returned as the output. The code should start with: ```python from typing im...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sort(arr: List[int]) -> List[int]: """ Sorts a list of integers in ascending order using the merge sort algorithm. Args: arr (List[int]): The list of integers to be sorted. Re...
python_sharegpt_23k
3,010
Write a Python function to remove an element from a list at a specified index while maintaining the order of the remaining elements. The function should have a time complexity of O(n), where n is the length of the list. Additionally, you are not allowed to use any built-in functions or methods that directly remove elem...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_element_at_index(lst: List[int], index: int) -> List[int]: """ Removes an element from the list at the specified index while maintaining the order of the remaining elements. The removal is...
python_sharegpt_23k
3,013
Write a Python function to generate the Fibonacci sequence up to the nth term efficiently, with a time complexity of O(n) and a constant space complexity. The function should handle large values of n (up to 100) without using recursion or any built-in mathematical functions. The function should also handle edge cases s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def fibonacci_sequence(n: int) -> List[int]: """ Generate the Fibonacci sequence up to the nth term efficiently with O(n) time complexity and constant space complexity. Args: n (int): The nu...
python_sharegpt_23k
3,018
Write a Python function to format a large number as a string into a more readable format by grouping digits into sets of three and separating them with commas. The function should handle both positive and negative numbers. The code should start with: ```python def format_number(number: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def format_number(number: str) -> str: """ Formats a large number as a string into a more readable format by grouping digits into sets of three and separating them with commas. Args: number (str): The number to be f...
python_sharegpt_23k
3,021
Write a Python function to split a given list of integers into two separate lists: one containing all the odd numbers and the other containing all the even numbers. The odd numbers should maintain their relative order in the original list, and the same should be true for the even numbers. If there are no odd numbers or...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def split_list(lst: List[int]) -> Tuple[List[int], List[int]]: """ Splits a list of integers into two lists: one containing all odd numbers and the other containing all even numbers. The relat...
python_sharegpt_23k
3,031
Write a Python function to count the number of occurrences of a target element in a sorted array and return the indices of all occurrences of the element. The function should have a time complexity of O(log n), where n is the size of the array. The array will contain at most 10^9 elements, and the target element will b...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def count_occurrences_and_indices(arr: List[int], target: int) -> Tuple[int, List[int]]: """ Counts the number of occurrences of a target element in a sorted array and returns the indices of all o...
python_sharegpt_23k
3,034
Write a Python function to detect a cycle in a linked list without using additional space and without modifying the linked list. The linked list may contain duplicate nodes, and the algorithm should identify if there is a cycle with at least two distinct nodes that are duplicates. The code should start with: ```python...
Here is the Python code to solve the given problem in the markdown block: ```python class ListNode: def __init__(self, value=0, next=None): self.value = value self.next = next def has_cycle_with_duplicates(head: ListNode) -> bool: """ Detects if there is a cycle in the linked list with at l...
python_sharegpt_23k
3,036
Write a Python function to remove all duplicates from an array of strings while preserving the order of the elements. Additionally, the resulting array should only contain strings that are palindromes. The program should not use any additional data structures or libraries to solve the problem. The code should start wit...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_duplicates_palindromes(arr: List[str]) -> List[str]: """ Remove all duplicates from an array of strings while preserving the order of the elements. Additionally, the resulting array should...
python_sharegpt_23k
3,037
Write a Python function to calculate the sum of each column in a given 2-dimensional array of size `n x m` and return the sums in a new array of size `m`. The function should handle arrays with any number of rows and columns. The code should start with: ```python from typing import List def column_sums(arr: List[List...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def column_sums(arr: List[List[int]]) -> List[int]: """ Calculate the sum of each column in a given 2-dimensional array and return the sums in a new array. Args: arr (List[List[int]]): A 2-d...
python_sharegpt_23k
3,038
Write a Python function to remove duplicate values from a given array, including nested arrays, without using any built-in methods or data structures (such as sets or dictionaries) to store unique values. The function should handle arrays containing non-integer values, including strings and nested arrays. The code shou...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Any def remove_duplicates(arr: List[Any]) -> List[Any]: """ Removes duplicate values from a given array, including nested arrays, without using any built-in methods or data structures. Args: ...
python_sharegpt_23k
3,040
Write a Python function to find the smallest positive integer that is not present in a given list of integers. The function should handle the following constraints and requirements: - The input list can contain up to 1,000,000 integers. - The input list can contain positive and negative integers. - The function should ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_smallest_positive_integer(lst: List[int]) -> int: """ Find the smallest positive integer that is not present in the given list. Args: lst (List[int]): A list of integers. Retur...
python_sharegpt_23k
3,042
Write a Python function to print the first 10 powers of a given number `x`, starting from `x^0`, without using the exponentiation operator or any built-in function that calculates powers. Implement your own function to calculate the power of `x`. The function should start with: ```python def print_powers_of_x(x: int): ...
Here is the Python code to solve the given problem in the markdown block: ```python def print_powers_of_x(x: int): """ Prints the first 10 powers of a given number x, starting from x^0, without using the exponentiation operator. Args: x (int): The base number whose powers are to be printed. Re...
python_sharegpt_23k
3,048
Write a Python function to sort a given array of integers using the Quick Sort algorithm. The function should be implemented in a recursive manner and should not use any built-in sorting functions or libraries. Additionally, ensure that the algorithm has a time complexity of O(nlogn) in all cases. The function should s...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def quicksort(arr: List[int]) -> List[int]: """ Sorts a given array of integers using the Quick Sort algorithm. Args: arr (List[int]): The array of integers to be sorted. Returns: ...
python_sharegpt_23k
3,058
Write a Python function to generate a list of 15 unique prime numbers within the range of 1000 to 10000, sorted in descending order. The function should ensure that all numbers in the list are unique and prime. The code should start with: ```python from typing import List def generate_unique_prime_list() -> List[int]...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def is_prime(n: int) -> bool: """ Check if a number is prime. Args: n (int): The number to check. Returns: bool: True if the number is prime, False otherwise. ...
python_sharegpt_23k
3,061
Write a Python function to find the second largest number and its frequency in a given array of integers. If there are multiple numbers with the same frequency, return the smallest number among them. The function should not use any built-in sorting functions or data structures and should solve the problem in O(n) time ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_second_largest_and_frequency(arr: List[int]) -> Tuple[int, int]: """ Find the second largest number and its frequency in a given array of integers. If there are multiple numbers with ...
python_sharegpt_23k
3,065
Write a Python function to convert an arbitrary number from any base between 2 and 36 to its decimal representation without using any built-in conversion functions or libraries. The function should handle numbers with up to 1000 digits and negative numbers correctly. The function should have a time complexity of O(n) a...
Here is the Python code to solve the given problem in the markdown block: ```python def base_to_decimal(number: str, base: int) -> int: """ Converts an arbitrary number from any base between 2 and 36 to its decimal representation. Args: number (str): The number to convert, represented as a string. ...
python_sharegpt_23k
3,067
Write a Python function to check if a target number exists in a given array and return its index position if it does. If the target number is negative, the function should return `False`. If the target number exists multiple times in the array, return the index position of the first occurrence. The function should star...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_target_number(arr: List[int], target: int) -> Tuple[bool, int]: """ Check if a target number exists in the given array and return its index position if it does. If the target number i...
python_sharegpt_23k
3,077
Write a Python function to filter an array and return a new array containing only the prime numbers greater than 2. The function should have a time complexity of O(n) and a space complexity of O(1), meaning it should not use any additional arrays or data structures. The function should not use any built-in functions or...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_prime(n: int) -> bool: """ Check if a number is prime. Args: n (int): The number to check for primality. Returns: bool: True if the number is prime, False otherwise. ...
python_sharegpt_23k
3,081
Write a Python function to merge two given dictionaries into a single dictionary. The keys in the merged dictionary should be sorted in descending order based on their values. The merged dictionary should only include keys that have values greater than or equal to 10. If there are duplicate keys with different values, ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def merge_dicts(dict1: Dict[str, int], dict2: Dict[str, int]) -> Dict[str, int]: """ Merge two dictionaries into a single dictionary. The keys in the merged dictionary are sorted in descending order ...
python_sharegpt_23k
3,085
Write a Python function to generate two lists: one containing 20 random integers within the range of 1 to 1000 (inclusive), and another containing 20 random prime numbers within the range of 1000 to 10000 (inclusive). The function should then calculate and return the sum of the numbers in the first list and the product...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple import random import math def is_prime(n: int) -> bool: """ Check if a number is prime. Args: n (int): The number to check. Returns: bool: True if the number is prime, Fa...
python_sharegpt_23k
3,087
Write a Python function that prints the string "Hello World" to the console using a nested loop. The outer loop should iterate 10 times, and each iteration of the outer loop should iterate the inner loop one more time than the previous iteration. The function should start with: ```python def print_hello_world_nested():...
Here is the Python code to solve the given problem in the markdown block: ```python def print_hello_world_nested(): """ Prints the string "Hello World" to the console using a nested loop. The outer loop iterates 10 times, and each iteration of the outer loop iterates the inner loop one more time than th...
python_sharegpt_23k
3,088
Implement an in-place modified version of the quicksort algorithm to sort the given array in descending order. The array may contain duplicate elements. The algorithm should have a time complexity of O(n log n) and should not use any additional data structures or recursion. Additionally, the algorithm should be optimiz...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def partition(arr: List[int], low: int, high: int) -> int: """ Partitions the array around a pivot such that elements greater than or equal to the pivot are on the left and elements less than or equa...
python_sharegpt_23k
3,093
Write a Python function to count the number of occurrences of a given integer value in an array of integers. The function should have a time complexity of O(n log n) and a space complexity of O(n). The input array will have a maximum length of 10^5, and the input value will be an integer between -10^9 and 10^9. The fun...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def count_occurrences(arr: List[int], value: int) -> int: """ Counts the number of occurrences of a given integer value in an array of integers. Args: arr (List[int]): The array of integers ...
python_sharegpt_23k
3,101
Write a Python function to determine whether a given string is a palindrome or not, considering alphanumeric characters only and ignoring case sensitivity. Additionally, the function should ignore all non-alphanumeric characters while determining if the string is a palindrome. The palindrome check should also take into...
Here is the Python code to solve the given problem in the markdown block: ```python import re def is_palindrome(string: str) -> bool: """ Determine whether a given string is a palindrome, considering alphanumeric characters only and ignoring case sensitivity. Args: string (str): The input string t...
python_sharegpt_23k
3,103
Write a Python function to count the occurrences of each letter in a given string, disregarding case sensitivity and excluding any non-alphabetic characters. Additionally, the function should return the count of vowels and consonants separately. The function must use recursion to solve this problem. The code should sta...
Here is the Python code to solve the given problem in the markdown block: ```python def count_letters(string: str) -> (int, int, dict): """ Count the occurrences of each letter in the given string, disregarding case sensitivity and excluding non-alphabetic characters. Additionally, count the number of vowel...
python_sharegpt_23k
3,106
Write a Python function to create a deep copy of a nested list, ensuring that any mutable objects within the list are also deep copied. The function should not use any built-in functions or libraries that directly perform deep copying. The solution should have a time complexity of O(n) and a space complexity of O(n), w...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Any def deep_copy_nested_list(nested_list: list) -> list: """ Creates a deep copy of a nested list, ensuring that any mutable objects within the list are also deep copied. Args: nested_list (list...
python_sharegpt_23k
3,112
Write a Python function to reverse a doubly linked list in O(n) time complexity using a recursive approach. You are not allowed to use any additional data structures or modify the values of the nodes. The function should return the new head of the reversed list. The code should start with: ```python class Node: de...
Here is the Python code to solve the given problem in the markdown block: ```python class Node: def __init__(self, value): self.value = value self.next = None self.prev = None def reverse_doubly_linked_list(node: Node) -> Node: """ Reverses a doubly linked list using a recursive app...
python_sharegpt_23k
3,117
Write a Python function to generate and print the Fibonacci series up to a given number `n`, but only if the number in the series is both prime and a perfect square. The given number `n` must also be greater than 1. The function should start with: ```python import math def print_fibonacci_prime_perfect_squares(n: int)...
Here is the Python code to solve the given problem in the markdown block: ```python import math def is_prime(n: int) -> bool: """ Check if a number is prime. Args: n (int): The number to check. Returns: bool: True if the number is prime, False otherwise. """ if n < 2: ...
python_sharegpt_23k
3,119
Write a Python function to determine if a given positive integer is a prime number. The function should check if the input is within the range of 2 to 10^9, inclusive. Additionally, optimize your solution to have a time complexity of O(sqrt(n)) where n is the input number. The function should also handle inputs in the ...
Here is the Python code to solve the given problem in the markdown block: ```python import math def is_prime_number(n: int) -> bool: """ Determine if a given positive integer is a prime number. Args: n (int): The positive integer to check for primality. Returns: bool: True if the numb...
python_sharegpt_23k
3,120
Write a Python function to reverse a string in-place without using any extra space or built-in functions. The function should have a time complexity of O(n), where n is the length of the input string. The function should start with: ```python def reverse_string_in_place(string: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def reverse_string_in_place(string: str) -> str: """ Reverses a string in-place without using any extra space or built-in functions. Args: string (str): The input string to be reversed. Returns: str: Th...
python_sharegpt_23k
3,128
Write a Python function to extract and return a list of unique even numbers from a given list of integers, sorted in ascending order. If the input list does not contain any even numbers, the function should return an empty list. The code should start with: ```python from typing import List def get_unique_even_element...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def get_unique_even_elements(A: List[int]) -> List[int]: """ Extracts and returns a list of unique even numbers from the given list of integers, sorted in ascending order. Args: A (List[int]...
python_sharegpt_23k
3,134
Write a Python function called `fizzBuzz` that takes an integer as an argument and returns a string based on the following conditions: - If the number is divisible by both 3 and 5, return "FizzBuzz". - If the number is divisible by 3, return "Fizz". - If the number is divisible by 5, return "Buzz". - If the number is n...
Here is the Python code to solve the given problem in the markdown block: ```python def fizzBuzz(num: int) -> str: """ Returns a string based on the divisibility of the input number. Args: num (int): The integer to check for divisibility. Returns: str: A string indicating the divisibil...
python_sharegpt_23k
3,135
Write a Python function to sort a given array of integers in descending order using an O(n^2) time complexity algorithm. The function should not use any built-in sorting functions or data structures. Additionally, the function should handle duplicate integers in the array and ensure that they are placed adjacent to eac...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_array_descending(arr: List[int]) -> List[int]: """ Sorts a given array of integers in descending order using an O(n^2) time complexity algorithm. The function does not use any built-in sorti...
python_sharegpt_23k
3,138
Write a Python function to sort a list of integers and floating-point numbers in descending order without using any built-in sorting functions or methods. The function should have a time complexity of O(n^2) and should not use any additional data structures. The input list can contain duplicate integers, negative integ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def custom_sort(lst: List[float]) -> List[float]: """ Sorts a list of integers and floating-point numbers in descending order using a custom bubble sort algorithm. Args: lst (List[float]): T...
python_sharegpt_23k
3,143
Write a Python function to remove any duplicate characters from a given string and sort the remaining characters in ascending order, in-place without using any extra space. The input string will only contain lowercase letters. The function should start with: ```python def remove_duplicates_and_sort(string: str) -> str:...
Here is the Python code to solve the given problem in the markdown block: ```python def remove_duplicates_and_sort(string: str) -> str: """ Removes any duplicate characters from the given string and sorts the remaining characters in ascending order, in-place without using any extra space. Args: str...
python_sharegpt_23k
3,144
Write a Python function to sort an array in descending order using the Bubble Sort algorithm. The function should not use any built-in sorting functions. The provided reference code contains a small error that needs to be identified and fixed to ensure the function works correctly. The code should start with: ```pytho...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_array_descending(arr: List[int]) -> List[int]: """ Sorts the given array in descending order using the Bubble Sort algorithm. Args: arr (List[int]): The array to be sorted. Ret...
python_sharegpt_23k
3,145
Write a Python function to select all prime numbers from a given array of integers and return a tuple containing the list of prime numbers and the sum of all prime numbers. The function should be efficient and correctly identify prime numbers using an optimized approach. The code should start with: ```python from typi...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def is_prime(n: int) -> bool: """ Check if a given number is prime. Args: n (int): The number to check for primality. Returns: bool: True if the number is prime, False ot...
python_sharegpt_23k
3,148
Write a Python function to classify a given sentence into either a question or an instruction. The function should analyze the sentence and determine if it is asking a question or giving an instruction. The code should start with: ```python def classify_sentence(sentence: str) -> str: ```
Here is the Python code to solve the given problem in the markdown block: ```python def classify_sentence(sentence: str) -> str: """ Classify a given sentence into either a question or an instruction. Args: sentence (str): The sentence to classify. Returns: str: The classification of t...
python_sharegpt_23k
3,152
Write a Python function to convert a given string of words to uppercase and replace all vowels with corresponding numbers (A=1, E=2, I=3, O=4, U=5). The converted string should have all words separated by a single whitespace and should not have any leading or trailing whitespaces. The input string will only contain alp...
Here is the Python code to solve the given problem in the markdown block: ```python def convert_string_to_uppercase_and_replace_vowels(input_string: str) -> str: """ Converts a given string of words to uppercase and replaces all vowels with corresponding numbers. Args: input_string (str): The input...
python_sharegpt_23k
3,157
Write a Python function to filter and return a list of words from a given string that meet the following criteria: 1. The word must be longer than 10 characters. 2. The word must contain at least one uppercase letter. 3. The word must contain at least one lowercase letter. 4. The word must contain at least one digit. 5...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def find_valid_words(string: str) -> List[str]: """ Filters and returns a list of words from the given string that meet the following criteria: 1. The word must be longer than 10 characters...
python_sharegpt_23k
3,162
Write a Python function to sort a given list of numbers in descending order using a well-optimized sorting algorithm with a time complexity of O(n log n) or better. Do not use any built-in sorting functions or libraries. Implement a sorting algorithm such as Merge Sort, Quick Sort, or Heap Sort. Ensure that the functio...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def sort_descending(arr: List[int]) -> List[int]: """ Sorts a given list of numbers in descending order using Merge Sort. Args: arr (List[int]): The list of numbers to be sorted. Return...
python_sharegpt_23k
3,163
Write a Python function to validate a 2D array of integers to ensure that each element is a unique prime number greater than 100. The function should return `True` if all elements meet the criteria, and `False` otherwise. The code should start with: ```python from typing import List def validate_prime_array(array: Lis...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_prime(n: int) -> bool: """ Helper function to check if a number is prime. Args: n (int): The number to check for primality. Returns: bool: True if the number is prime, Fa...
python_sharegpt_23k
3,166
Write a Python function to calculate the base-2 logarithm of a given positive integer using only bitwise operations. The function should handle cases where the input integer is not a power of 2. The code should start with: ```python def base_2_logarithm(n: int) -> int: ```
Here is the Python code to solve the given problem in the markdown block: ```python def base_2_logarithm(n: int) -> int: """ Calculate the base-2 logarithm of a given positive integer using only bitwise operations. Args: n (int): The positive integer for which to calculate the base-2 logarithm. ...
python_sharegpt_23k
3,170
Write a Python function to check if a given string contains both alphabets and numbers in a specific order, where all alphabets must appear before any number. The function should return `True` if the string meets the criteria, and `False` otherwise. The input string can be a mix of upper and lower case alphabets and nu...
Here is the Python code to solve the given problem in the markdown block: ```python def check_string_order(s: str) -> bool: """ Check if the input string contains both alphabets and numbers in a specific order, where all alphabets must appear before any number. Args: s (str): The input string t...
python_sharegpt_23k
3,172
Write a Python function to create a new array that is a copy of the given input array, consisting of all elements smaller than 5. Additionally, the new array should only contain prime numbers and the length of the new array should not exceed 5. If there are no prime numbers smaller than 5, the new array should be empty...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_prime(num: int) -> bool: """ Check if a number is prime. Args: num (int): The number to check. Returns: bool: True if the number is prime, False otherwise. """ if...
python_sharegpt_23k
3,180
Write a Python function to find and return a list of integers that occur more than once in a given list of integers. The function should not modify the original list and should handle cases where the input list may contain negative numbers, be empty, or contain duplicate elements in any order. The function should start...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_unique_duplicates(nums: List[int]) -> List[int]: """ Find and return a list of integers that occur more than once in the given list. Args: nums (List[int]): The list of integers to ...
python_sharegpt_23k
3,187
Write a Python function to check if a given string is a palindrome or not. The function should have a time complexity of O(n) and should not use any additional space other than the input string. Additionally, the function should not use any built-in string manipulation methods or libraries. The code should start with: ...
Here is the Python code to solve the given problem in the markdown block: ```python def is_palindrome(string: str) -> bool: """ Check if the given string is a palindrome. Args: string (str): The string to check. Returns: bool: True if the string is a palindrome, False otherwise. ""...
python_sharegpt_23k
3,196
Write a Python function to compute the product of each pair of adjacent elements in a given list of integers. The function should return a new list containing these products. The code should start with: ```python from typing import List def adjacent_products(original_list: List[int]) -> List[int]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def adjacent_products(original_list: List[int]) -> List[int]: """ Compute the product of each pair of adjacent elements in the given list of integers. Args: original_list (List[int]): The li...
python_sharegpt_23k
3,199
Write a Python function to remove all duplicates from a given array and return a new array with the remaining elements sorted in ascending order. The input array will not contain any negative numbers and will have a length of at most 100. The function must solve the problem in O(n) time complexity without using any add...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def remove_duplicates(arr: List[int]) -> List[int]: """ Removes all duplicates from the given array and returns a new array with the remaining elements sorted in ascending order. Args: arr (...
python_sharegpt_23k
3,201
Write a Python function to modify a given list by removing all strings with length less than three and any strings that contain numbers. The modified list should be sorted in reverse alphabetical order, and any duplicate strings should be removed. The function should not use any built-in Python methods or functions suc...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def modify_list(lst: List[str]) -> List[str]: """ Modifies the given list by removing all strings with length less than three, any strings that contain numbers, and then sorts the list in reverse alp...
python_sharegpt_23k
3,204
Write a Python function to perform a binary search in a sorted array of strings with up to 10 million elements. The function should return the index of the first occurrence of the target string. If the target string is not found, the function should return -1. The time complexity of the function should be O(log n), whe...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def binary_search_first_occurrence(arr: List[str], target: str) -> int: """ Perform a binary search to find the index of the first occurrence of the target string in a sorted array. Args: ar...
python_sharegpt_23k
3,206
Implement a quicksort algorithm that handles duplicate elements in the input array. The algorithm should be able to sort an array of integers efficiently, even when the array contains duplicate elements. The code should start with: ```python from typing import List def quicksort_with_duplicates(arr: List[int]) -> List...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def quicksort_with_duplicates(arr: List[int]) -> List[int]: """ Sorts an array of integers using the quicksort algorithm, handling duplicate elements. Args: arr (List[int]): The array of int...
python_sharegpt_23k
3,209
Write a Python function to combine two lists without duplication and in alphabetical order, without using any built-in sorting or deduplication functions/methods. The function should start with: ```python from typing import List def combine_and_sort_lists(list_one: List[str], list_two: List[str]) -> List[str]: ```
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def combine_and_sort_lists(list_one: List[str], list_two: List[str]) -> List[str]: """ Combines two lists without duplication and sorts them in alphabetical order. Args: list_one (List[str])...
python_sharegpt_23k
3,220
Write a Python function to validate an email address based on the following criteria: 1. The email address must contain at least one uppercase letter. 2. The email address must contain at least one lowercase letter. 3. The email address must contain at least one digit. 4. The email address must contain at least one spe...
Here is the Python code to solve the given problem in the markdown block: ```python import re def validate_email(email: str) -> bool: """ Validates an email address based on the following criteria: 1. The email must contain at least one uppercase letter. 2. The email must contain at least one lowercase...
python_sharegpt_23k
3,231
Write a Python function to calculate the sum of prime numbers in a given list, determine the largest and smallest prime numbers, and return the prime numbers in descending order. The function should not use any built-in functions for prime number generation or checking, and the time complexity should be O(n), where n i...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def prime_operations(prime_numbers: List[int]) -> (int, int, int, List[int]): """ Calculate the sum of prime numbers in the given list, determine the largest and smallest prime numbers, and return th...
python_sharegpt_23k
3,245
Write a Python function to compare two dictionaries by both key and value, ensuring that the keys are strings, the values are positive integers, and the dictionaries cannot contain more than 10 key-value pairs. The function should return `True` if both dictionaries are identical in terms of keys and values, and `False`...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import Dict def compare_dictionaries(dict1: Dict[str, int], dict2: Dict[str, int]) -> bool: """ Compare two dictionaries to ensure they have the same keys and values, and that the keys are strings and the values...
python_sharegpt_23k
3,248
Write a Python function to identify and return a list of palindromic strings from a given list of strings. A palindrome is a word or phrase that reads the same backward as forward, ignoring spaces, punctuation, and capitalization. The function should have a time complexity of O(n), where n is the length of the input li...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import re def get_palindromic_strings(strings: List[str]) -> List[str]: """ Returns a list of strings that are palindromes from the given list of strings. A palindrome is a word or phrase that reads...
python_sharegpt_23k
3,250
Write a Python function to convert a list of strings into a dictionary where the keys are the unique strings from the list and the values are the lengths of the corresponding strings. The function should remove any duplicate strings from the list before converting it into a dictionary. The function should have a time c...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Dict def convert_list_to_dict(lst: List[str]) -> Dict[str, int]: """ Converts a list of strings into a dictionary where the keys are the unique strings from the list and the values are the lengths o...
python_sharegpt_23k
3,253
Write a Python function to generate Fibonacci numbers less than or equal to a given integer `n`. The function should adhere to the following constraints: 1. Accept a parameter `n` which represents the upper limit of the Fibonacci numbers to be generated. 2. Return a list of Fibonacci numbers less than or equal to `n`. ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_fibonacci_numbers(n: int) -> List[int]: """ Generate a list of Fibonacci numbers less than or equal to the given integer 'n'. Args: n (int): The upper limit for the Fibonacci nu...
python_sharegpt_23k
3,256
Write a Python function to compute the sum of all positive even numbers in a given array using recursion. The array should only contain integers and have at least 10 elements. The function should handle cases where the array contains negative numbers and zeros by ignoring these values and only considering positive even...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def sum_positive_even_numbers(arr: List[int]) -> List[Tuple[int, int]]: """ Compute the sum of all positive even numbers in a given array using recursion. The function returns a list of tuples...
python_sharegpt_23k
3,260
Write a Python function to append a character at the start and end of a given string. The character to be appended at the end should be the same as the character at the start of the string. The length of the input string should be greater than or equal to 3, and the characters in the string should only be alphabets. Th...
Here is the Python code to solve the given problem in the markdown block: ```python def append_character(string: str) -> str: """ Appends the first character of the input string at the start and end of the string. Args: string (str): The input string to be modified. Returns: str: The m...
python_sharegpt_23k
3,262
Write a Python function to perform a binary search on a sorted array `nums` to find the index of the first occurrence of a target element `target`. If the target is not found, return -1. The function should run in O(log n) time complexity. The input array `nums` may contain duplicates, and the function should return th...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def binary_search_first_occurrence(nums: List[int], target: int) -> int: """ Perform a binary search on a sorted array to find the index of the first occurrence of a target element. If the target is ...
python_sharegpt_23k
3,264
Write a Python function to count the number of times a given pattern appears as a whole word in a given string. The pattern can contain special characters and can be case-sensitive. The pattern should only be counted if it appears as a whole word and not as a substring within another word. The function should handle th...
Here is the Python code to solve the given problem in the markdown block: ```python import re def count_whole_word_occurrences(string: str, pattern: str) -> int: """ Counts the number of times a given pattern appears as a whole word in a given string. The pattern can contain special characters and can be ...
python_sharegpt_23k
3,266
Write a Python function to generate a specified number of unique random numbers within a given range without using any built-in random number generator functions or libraries. The function should ensure that no duplicate numbers are generated. The code should start with: ```python from typing import List def generate_...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def generate_unique_random_numbers(lower: int, upper: int, count: int) -> List[int]: """ Generate a specified number of unique random numbers within a given range. Args: lower (int): The low...
python_sharegpt_23k
3,267
Write a Python function to match each string in a list of tuples with a corresponding pattern and return a new list containing `True` or `False` based on whether the pattern matches the string. Each tuple in the input list contains a string and a pattern, where the pattern is a valid regular expression. The function sh...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple import re def match_strings(patterns: List[Tuple[str, str]]) -> List[bool]: """ Matches each string in a list of tuples with a corresponding pattern and returns a list of booleans. Args: ...
python_sharegpt_23k
3,268
Write a Python function to detect if a given sentence contains any curse words without using the `in` operator or any string matching methods (such as `find()` or `index()`). The function should return `True` if there is a curse word in the sentence, otherwise `False`. The code should start with: ```python from typing...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def contains_curse_words(sentence: str, curse_words: List[str]) -> bool: """ Detects if a given sentence contains any curse words without using the `in` operator or string matching methods. Args: ...
python_sharegpt_23k
3,274
Write a Python function to iterate over all items in a list and return a new list where each item is multiplied by its index if the item is numeric (integer or float). If the item is non-numeric, append a string indicating the index where the non-numeric value was found. The function should handle lists containing any ...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def multiply_by_index(my_list: List[Union[int, float, str]]) -> List[Union[int, float, str]]: """ Iterates over a list and returns a new list where each numeric item is multiplied by its index, ...
python_sharegpt_23k
3,279
Write a Python function to find the minimum absolute difference between two elements from two given lists of integers. The function should have a time complexity of O(nlogn), where n is the total number of elements in both lists combined. The function should not use any built-in sorting algorithms or functions. The cod...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def merge_sort(arr: List[int]) -> List[int]: """ Sorts the input list using the merge sort algorithm. Args: arr (List[int]): The list of integers to be sorted. Returns: List[int...
python_sharegpt_23k
3,289
Write a Python function that demonstrates the concept of closures by creating a function that returns another function. The returned function should be able to access and modify the state of the outer function. Additionally, provide a piece of erroneous code that attempts to use closures but contains a logical error. E...
Here is the Python code to solve the given problem in the markdown block: ```python def create_closure(initial_value: int) -> callable: """ Creates a closure that captures the initial value and returns a function that increments it. Args: initial_value (int): The initial value to be captured by the...
python_sharegpt_23k
3,293
Write a Python function to perform division of two numbers, a numerator and a denominator, without using the division operator (`/`), any built-in functions that perform division, or any mathematical operations that involve division. Additionally, you are not allowed to use the multiplication operator (`*`) or any buil...
Here is the Python code to solve the given problem in the markdown block: ```python def divide_without_division(numerator: int, denominator: int) -> float: """ Perform division of two numbers without using the division operator or any built-in division functions. Args: numerator (int): The numerato...
python_sharegpt_23k
3,294
Write a Python function named `my_function` that takes an integer `x` as input. The function should continuously increment `x` by 1 as long as `x` is greater than 1000 and is divisible by 3. The function should return the final value of `x` after the loop terminates. The code should start with: ```python def my_functi...
Here is the Python code to solve the given problem in the markdown block: ```python def my_function(x: int) -> int: """ Increments the input integer `x` by 1 as long as `x` is greater than 1000 and divisible by 3. Args: x (int): The input integer to be incremented. Returns: int: The fi...
python_sharegpt_23k
3,302
Write a Python function to generate a random user agent string that includes the name, version, and operating system of a specific web browser. Additionally, the user agent string should contain a randomly generated string of characters as a unique identifier for each user. The solution should have a time complexity of...
Here is the Python code to solve the given problem in the markdown block: ```python import random import string def generate_user_agent(browser_name: str, browser_version: str, operating_system: str) -> str: """ Generate a random user agent string that includes the name, version, and operating system of a spec...
python_sharegpt_23k
3,303
Write a Python function to add two positive integers using only bitwise operators (AND, OR, NOT) and without using the XOR and shift operators. The time complexity should be O(log n), where n is the maximum number of bits required to represent the input numbers. The code should start with: ```python def add_numbers_bi...
Here is the Python code to solve the given problem in the markdown block: ```python def add_numbers_bitwise(a: int, b: int) -> int: """ Adds two positive integers using only bitwise operators (AND, OR, NOT) and without using XOR and shift operators. Args: a (int): The first positive integer. ...
python_sharegpt_23k
3,309
Write a Python function to extract prime numbers from a given list of integers. The function should have a time complexity of O(n*(log(m))^2), where n is the length of the original list and m is the maximum value in the original list. The space complexity can remain the same. The code should start with: ```python from...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import math def is_prime(n: int) -> bool: """ Check if a number is prime. Args: n (int): The number to check for primality. Returns: bool: True if the number is prime, False oth...
python_sharegpt_23k
3,311
Write a Python function to find the index of the last occurrence of a target integer in a given list of integers. If the target integer is not present in the list, the function should return -1. The list is not sorted. The code should start with: ```python from typing import List def find_last_occurrence(lst: List[in...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def find_last_occurrence(lst: List[int], target: int) -> int: """ Find the index of the last occurrence of a target integer in a list. Args: lst (List[int]): The list of integers to search. ...
python_sharegpt_23k
3,335
Write a Python function to find the maximum and minimum elements in an array along with their indices using the sequential search algorithm. The function should return the maximum and minimum elements along with their first occurrence indices. The function should handle edge cases such as an empty array and arrays with...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Tuple def find_max_min_elements(arr: List[int]) -> Tuple[int, int, int, int]: """ Find the maximum and minimum elements in an array along with their indices using sequential search. Args: a...
python_sharegpt_23k
3,342
Write a Python function to remove duplicate elements from a given array while maintaining the original order of the elements. The array may contain both integers and strings. The array will have at most 1000 elements. The function should start with: ```python from typing import List, Union def remove_duplicates(arr: L...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List, Union def remove_duplicates(arr: List[Union[int, str]]) -> List[Union[int, str]]: """ Removes duplicate elements from the given array while maintaining the original order of the elements. Args: ...
python_sharegpt_23k
3,347
Write a Python function to generate a random array of size `n` containing unique elements sorted in ascending order. The function should have a time complexity of O(n) and a space complexity of O(1). The code should start with: ```python from typing import List import random def generate_sorted_unique_array(n: int) ->...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List import random def generate_sorted_unique_array(n: int) -> List[int]: """ Generate a random array of size `n` containing unique elements sorted in ascending order. Args: n (int): The size of ...
python_sharegpt_23k
3,349
Write a Python function to find all prime numbers within a given range [start, end]. The function should handle invalid ranges where the start integer is greater than the end integer by returning an empty list. The function should have a time complexity of O(n) or better, where n is the size of the range. The code sho...
Here is the Python code to solve the given problem in the markdown block: ```python from typing import List def is_prime(n: int) -> bool: """ Check if a number is prime. Args: n (int): The number to check for primality. Returns: bool: True if the number is prime, False otherwise. ...