"""
Example 1
"""

a = -2000
b =  4001
c =  6002
my_var = c // a, b or a, c % a
c, b, a = my_var
print(type(my_var))
print(a, b, c)

# Answer
# <class 'tuple'>
# -1998 4001 -4

"""
Example 2
"""

s = 'Abrakadabra'
d = {}
for c in s:
  if c in d.keys():
    d[c] = d[c] + 1
  else:
    d[c] = 1
print(d)

"""
Example 2; with recursion
"""

def count_chars_recursive(s, index=0, d=None):
    if d is None:
        d = {}

    # Base case: if we've reached the end of the string, return the dictionary
    if index == len(s):
        return d

    # Current character
    c = s[index]

    # Update the dictionary
    if c in d:
        d[c] += 1
    else:
        d[c] = 1

    # Recursive call for the next character
    return count_chars_recursive(s, index + 1, d)

# Example usage
s = "Abrakadabra"
d_recursive = count_chars_recursive(s)
print(d_recursive)

"""
Example 3: Mutable objects, global and local variable scope
"""

# Let's manage a candy stash!
candies = 10  # Global variable representing the candy stash

# Function to restock candies (demonstrates local scope)
def restock_candies(amount):
    candies = amount  # Local variable
    return f"Restocked locally to {candies} candies (doesn't affect the global stash)."

# Function to eat candies (demonstrates use of 'global')
def eat_candies(amount):
    global candies
    if candies >= amount:
        candies -= amount
        return f"Ate {amount} candies. Remaining stash: {candies}."
    else:
        return f"Not enough candies to eat {amount}! Stash: {candies}."

# Function to share candies from a bag (demonstrates mutability)
def share_candies(bag):
    bag.append("surprise")
    return f"Candies in the bag after sharing: {bag}"

# Example usage
print(restock_candies(50))  # Local restocking
print(eat_candies(3))       # Modifies the global stash
bag_of_candies = ["chocolate", "gum"]
print(share_candies(bag_of_candies))  # Mutates the bag
print(f"Bag of candies after sharing: {bag_of_candies}")

"""
Example 4: String sorting, sets, lists
"""

# Input string
s = "crepes are awesome"

# Convert string to a set to remove duplicates
# Convert set to a list and sort it in reverse alphabetical order
sorted_chars = sorted(list(set(s)), reverse=True)

# Print the result
print("Original String:", s)
print("Sorted Unique Characters in Reverse Order:", sorted_chars)