Skip to the content.

3.2 Homework

# Creating a dictionary with at least 3 keys
my_dict = {
    "fruit": "apple",
    "color": "red",
    "quantity": 5
}

# Printing the dictionary
print(my_dict)
{'fruit': 'apple', 'color': 'red', 'quantity': 5}
# Starting dictionary
person = {"name": "Alice", "age": 30}

# Updating the age to 31
person["age"] = 31

# Printing the updated dictionary
print(person)

{'name': 'Alice', 'age': 31}
# Step 1: Create a dictionary
snack = {
    "name": "popcorn",
    "flavor": "butter",
    "quantity": 10
}

# Step 2: Update the 'quantity' item
snack["quantity"] = 15

# Step 3: Add a new item for 'price'
snack["price"] = 3.50

# Print the updated dictionary
print(snack)

{'name': 'popcorn', 'flavor': 'butter', 'quantity': 15, 'price': 3.5}
# Function to add two integers
def add_two_numbers(a, b):
    return a + b

# Define the integers
num1 = 5
num2 = 7

# Call the function and print the result
result = add_two_numbers(num1, num2)
print("The sum is:", result)

The sum is: 12