Loops for lists, tuples, dicts

Tpl = (1,8,2,4,3,5,7,6,9,0)
Lst = [1,2,2,3,3,3,1.1,2.1,3.1]
Dct1 = dict(name = "Aga", age = 35, year = 1989, hobby = "dance")
Dct2 = {'zodiac': "Cancer",'hair': "brown",'sex': "woman"}

for x in Tpl:
    print(x)
for x in sorted(Lst):
    print(x)
for item in Dct1:
    print(item)
for val in Dct1.values(): 
    print(val)

#Tuples

def calcs(a,b,c):
    return a+b, a**a, b/a, b**c
print(calcs(1,2,3))

names = ("Peter", "Cassandra", "April")
ages = (22, 47, 89)
for name, age in zip(names,ages):
    print(f"{name} is {age} years old")

t_array = ((1,2),(3,4),(5,6))

for in_tuple in t_array:
    for item in in_tuple:
        print(item, end = "::")
    print()

even_numbers = sorted(tuple(num for num in Tpl if num % 2 == 0))
squared_numbers = tuple(num ** 2 for num in Tpl)
print(even_numbers)
print(squared_numbers)

# A dictionary with tuple keys
points = {
    (1, 2): 'low',
    (3, 4): 'medium',
    (5, 6): 'high'
}

# Iterate through the dictionary items
for coordinates, label in points.items():
    print(f"Point {coordinates} is a {label} score")

#Dictionaries and lists


Lst = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

# Dictionary to hold even and odd numbers
categorized_numbers = {"even": [], "odd": []}

# Loop through each number in the list
for number in Lst:
    # Check if the number is even
    if number % 2 == 0:
        categorized_numbers["even"].append(number)
    else:
        categorized_numbers["odd"].append(number)

# Print the categorized numbers
print(categorized_numbers)

#Calculates the average grade for each worker

workers = {
    "Peter": [5, 4, 5],
    "Cassandra": [3, 4, 4],
    "April": [2, 1, 3]
}

# Dictionary to hold the average grades and pass/fail status
workers_score = {}

# Loop through each student in the dictionary
for student, grades in workers.items():
    # Calculate the average grade
    average_grade = round((sum(grades) / len(grades)),2)

    # Determine if the student passed
    if average_grade >= 3.5:
        status = "Passed"
    else:
        status = "Failed"

    # Store the result in the dictionary
    workers_score[student] = {"average": average_grade, \
                              "status": status}

# Print the student results
print(workers_score)

#Example from AI – manages an inventory of items

inventory = {
    "apples": 10,
    "bananas": 5,
    "oranges": 8
}

sales = {
    "apples": 4,
    "oranges": 2
}

restocks = {
    "bananas": 10,
    "oranges": 5
}

# Update inventory based on sales
for item, quantity_sold in sales.items():
    if item in inventory:
        inventory[item] -= quantity_sold

# Update inventory based on restocks
for item, quantity_restocked in restocks.items():
    if item in inventory:
        inventory[item] += quantity_restocked
    else:
        inventory[item] = quantity_restocked

# Print the updated inventory
print(inventory)