Write a function reverse_first_half(s) that returns a new string in which the first half of s is reversed and the second half is left as it is. The first half is the first len(s) // 2 characters; so when s has an odd length, its middle character belongs to the second half.
NOTE: This is a function type question, you don't have to take input or print the output, just have to complete the required function definition.
reverse_first_half("abcdef") -> 'cbadef'
reverse_first_half("python") -> 'typhon'
Implement this function:
def reverse_first_half(s: str) -> str:
Write the function only — the arguments are read for you and the return value is printed automatically.
Arguments arrive as one Python literal per line, in this order: s.
Input
"abcdef"
Output
'cbadef'
Write a function `reverse_first_half(s)` that returns a new string in which the first half of `s` is reversed and the second half is left as it is. The first half is the first `len(s) // 2` characters; so when `s` has an odd length, its middle character belongs to the second half. NOTE: This is a function type question, you don't have to take input or print the output, just have to complete the required function definition. ### Example ``` reverse_first_half("abcdef") -> 'cbadef' reverse_first_half("python") -> 'typhon' ``` ## Your task Implement this function: ```python def reverse_first_half(s: str) -> str: ``` Write the function only — the arguments are read for you and the return value is printed automatically. **Arguments** arrive as one Python literal per line, in this order: `s`. ## Example **Input** ``` "abcdef" ``` **Output** ``` 'cbadef' ``` `passenger` is a dictionary with the keys `"age"` and `"has_id"` (`True` or `False`). Write a function `train_ticket(passenger, available_seats)` that checks these rules in this order and returns the answer of the first rule that applies: 1. If the passenger has no ID, return `"ID Required"`. 2. If `available_seats` is 0, return `"Waiting List"`. 3. If the passenger is 60 years old or older, return `"Priority Booking"`. 4. Otherwise, return `"Ticket Confirmed"`. NOTE: This is a function type question, you don't have to take input or print the output, just have to complete the required function definition. ### Example ``` train_ticket({"age": 65, "has_id": True}, 5) -> 'Priority Booking' train_ticket({"age": 30, "has_id": False}, 5) -> 'ID Required' ``` ## Your task Implement this function: ```python def train_ticket(passenger: dict, available_seats: int) -> str: ``` Write the function only — the arguments are read for you and the return value is printed automatically. **Arguments** arrive as one Python literal per line, in this order: `passenger`, `available_seats`. ## Example **Input** ``` {"age": 65, "has_id": True} 5 ``` **Output** ``` 'Priority Booking' ``` Write a function `double_if_even_else_square(n)` that returns `n` multiplied by 2 if `n` is even, and the square of `n` if `n` is odd. NOTE: This is a function type question, you don't have to take input or print the output, just have to complete the required function definition. ### Example ``` double_if_even_else_square(8) -> 16 double_if_even_else_square(9) -> 81 ``` ## Your task Implement this function: ```python def double_if_even_else_square(n: int) -> int: ``` Write the function only — the arguments are read for you and the return value is printed automatically. **Arguments** arrive as one Python literal per line, in this order: `n`. ## Example **Input** ``` 8 ``` **Output** ``` 16 ```