#Popcorn Hack 3.2.1
def add_two_numbers(num1, num2):
"""Function to add two integers."""
return num1 + num2
# Get user input
try:
# Prompt the user for two integers
first_number = int(input("Enter the first integer: "))
second_number = int(input("Enter the second integer: "))
# Call the function to add the numbers
result = add_two_numbers(first_number, second_number)
# Print the result
print(f"The sum of {first_number} and {second_number} is: {result}")
except ValueError:
print("Please enter valid integers.")
The sum of 1 and 2 is: 3
#Popcorn Hack 3.2.2
# Creating a dictionary
person = {
"name": "Alice",
"age": 25,
"is_student": False
}
# Update an item in the dictionary
person["age"] = 26 # Updating Alice's age
# Adding a new item (a new person entry in this case)
person["David"] = {
"name": "David",
"age": 22,
"is_student": True
}
# Printing the updated dictionary
print(person)
{'name': 'Alice', 'age': 26, 'is_student': False, 'David': {'name': 'David', 'age': 22, 'is_student': True}}
# Starting dictionary
person = {
"name": "Alice",
"age": 30
}
# i. Update the age to 31
person["age"] = 31
# ii. Print the updated dictionary
print("Updated Person Dictionary:", person)
Updated Person Dictionary: {'name': 'Alice', 'age': 31}