Midterm: Programming Design 2026.
01. Define a function format_date_with_padding_zero() which formats month and day with padding zero.
def format_date_with_padding_zero(yyyy: int, mm: int, dd: int) -> str:
"""
>>> format_date_with_padding_zero(2023, 9, 9)
'2023-09-09'
>>> format_date_with_padding_zero(2023, 9, 10)
'2023-09-10'
>>> format_date_with_padding_zero(2023, 10, 9)
'2023-10-09'
>>> format_date_with_padding_zero(2023, 10, 10)
'2023-10-10'
>>> format_date_with_padding_zero(2024, 1, 1)
'2024-01-01'
"""
### BEGIN SOLUTION
### END SOLUTIONdef semantic_typing(x) -> str:
"""
>>> semantic_typing(5566)
'The type of your input 5566 is integer.'
>>> semantic_typing(3.1415)
'The type of your input 3.1415 is float.'
>>> semantic_typing(False)
'The type of your input False is boolean.'
>>> semantic_typing(True)
'The type of your input True is boolean.'
>>> semantic_typing("Python")
'The type of your input Python is string.'
"""
### BEGIN SOLUTION
### END SOLUTIONdef semantic_calculator(x: int, y: int, operator: str):
"""
>>> semantic_calculator(55, 66, "+")
121
>>> semantic_calculator(55, 66, "-")
-11
>>> semantic_calculator(3, 5, "*")
15
>>> semantic_calculator(3, 5, "/")
0.6
>>> semantic_calculator(3, 5, "//")
0
>>> semantic_calculator(3, 5, "**")
243
"""
### BEGIN SOLUTION
### END SOLUTION04. Define a function is_palindrome() which returns False if input string is not a palindrome word, otherwise returns True.
Source: https://en.wikipedia.org/wiki/Palindrome
def is_palindrome(x: str) -> bool:
"""
>>> is_palindrome("yay")
True
>>> is_palindrome("radar")
True
>>> is_palindrome("level")
True
>>> is_palindrome("python")
False
>>> is_palindrome("data")
False
"""
### BEGIN SOLUTION
### END SOLUTION05. Define a function remove_duplicates_and_sort() which removes duplicate elements for *args then sort with ascending order.
def remove_duplicates_and_sort(*args) -> list:
"""
>>> remove_duplicates_and_sort(2, 3, 5, 7, 11, 11, 7, 5, 3, 2)
[2, 3, 5, 7, 11]
>>> remove_duplicates_and_sort(13, 17, 19, 23, 29, 31, 31, 29, 23, 19, 17, 13)
[13, 17, 19, 23, 29, 31]
>>> remove_duplicates_and_sort(10, 9, 8, 6, 4, 1, 1, 4, 6, 8, 9, 10)
[1, 4, 6, 8, 9, 10]
"""
### BEGIN SOLUTION
### END SOLUTION06. Define a function range_primes() which returns a range of primes given start(inclusive) and stop(exclusive).
Source: https://en.wikipedia.org/wiki/Prime_number
def range_primes(start: int, stop: int):
"""
>>> range_primes(0, 5)
[2, 3]
>>> range_primes(6, 15)
[7, 11, 13]
>>> range_primes(17, 30)
[17, 19, 23, 29]
>>> range_primes(31, 37)
31
>>> range_primes(35, 37)
None
"""
### BEGIN SOLUTION
### END SOLUTION07. Define a function range_fizz_buzz() which returns a range of fizz-buzz numbers/strings given start(inclusive) and stop(exclusive).
Source: https://en.wikipedia.org/wiki/Fizz_buzz
def range_fizz_buzz(start: int, stop: int) -> list:
"""
>>> range_fizz_buzz(1, 6)
[1, 2, 'Fizz', 4, 'Buzz']
>>> range_fizz_buzz(6, 11)
['Fizz', 7, 8, 'Fizz', 'Buzz']
>>> range_fizz_buzz(11, 16)
[11, 'Fizz', 13, 14, 'Fizz Buzz']
"""
### BEGIN SOLUTION
### END SOLUTION08. Define a function find_idxmin_idxmax() which finds the indices of minimum and maximum values, respectively given a list.
def find_idxmin_idxmax(x: list) -> dict:
"""
>>> find_idxmin_idxmax([2, 3, 5, 7, 11])
{'idxmin': [0], 'idxmax': [4]}
>>> find_idxmin_idxmax([2, 3, 5, 7, 11, 11, 7, 5, 3, 2])
{'idxmin': [0, 9], 'idxmax': [4, 5]}
>>> find_idxmin_idxmax([10, 9, 8, 6, 4, 1])
{'idxmin': [5], 'idxmax': [0]}
>>> find_idxmin_idxmax([10, 9, 8, 6, 4, 1, 1, 4, 6, 8, 9, 10])
{'idxmin': [5, 6], 'idxmax': [0, 11]}
"""
### BEGIN SOLUTION
### END SOLUTION- For words that begin with consonant sounds, all letters before the initial vowel are placed at the end of the word sequence. Then, "ay" is added. e.g. "pig" -> "igpay". When words begin with consonant clusters (multiple consonants that form one sound), the whole sound is added to the end. e.g. "smile" -> "ilesmay"
- For words that begin with vowel sounds, the vowel is left alone, and "yay" is added to the end. e.g. "eat" -> "eatyay"
Source: https://en.wikipedia.org/wiki/Pig_Latin
def pig_latin(x: str) -> str:
"""
>>> pig_latin("pig")
'igpay'
>>> pig_latin("smile")
'ilesmay'
>>> pig_latin("eat")
'eatyay'
"""
### BEGIN SOLUTION
### END SOLUTION10. Define a function fibonacci() which returns the famous Fibonacci sequence in a list given a, b ($a \le b$ ) and length as parameters.
Source: https://en.wikipedia.org/wiki/Fibonacci_sequence
def fibonacci(a: int, b: int, length: int) -> list:
"""
>>> fibonacci(0, 1, 5)
[0, 1, 1, 2, 3]
>>> fibonacci(0, 1, 7)
[0, 1, 1, 2, 3, 5, 8]
>>> fibonacci(0, 1, 11)
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
"""
### BEGIN SOLUTION
### END SOLUTION