"""
Recommended Python Style Guide:
https://peps.python.org/pep-0008/#introduction
"""

import math

# ---------------------------
# Exercise 1: Accessing tuple elements
# ---------------------------
print("Exercise 1:")

tuple_icc = ("icc", "theory", "exercises")

# Access specific elements
print(tuple_icc[0], tuple_icc[2])

# Unpacking the tuple
first, second, _ = tuple_icc
print(first, second)

# ---------------------------
# Exercise 2: Iterating through a tuple
# ---------------------------
print("Exercise 2:")

fruits = ('strawberry', 'peach', 'mango', 'papaya', 'passion fruit')

# Loop through each element in the tuple
for fruit in fruits:
    print(fruit)

# ---------------------------
# Exercise 3: Membership check in a tuple
# ---------------------------
print("Exercise 3:", 'peach' in fruits)

# ---------------------------
# Exercise 4: Demonstrating tuple immutability
# ---------------------------
# Uncommenting the following line will raise a TypeError, as tuples are immutable:
# fruits[1] = 'strawberry'

# ---------------------------
# Exercise 5: Splitting a tuple into two parts
# ---------------------------

# Function to split a tuple into two halves.
# The first half contains an extra item if the tuple has an odd length.


def split_tuple(input_tuple):
    midpoint = math.ceil(len(input_tuple) / 2)  # Calculate midpoint using ceil
    return input_tuple[:midpoint], input_tuple[midpoint:]


print("Exercise 5 - Sliced Tuple:", split_tuple(fruits))

# Alternative approach, using integer division


def split_tuple_alternative(input_tuple):
    midpoint = len(input_tuple) // 2  # Integer division for midpoint
    return input_tuple[:midpoint + 1], input_tuple[midpoint + 1:]


print("Exercise 5 - Alternative Sliced Tuple:", split_tuple_alternative(fruits))
