def add_key_value(dictionary, key, value):
"""
Adds a key-value pair to the dictionary.
Args:
dictionary (dict): The dictionary to update.
key: The key to add.
value: The value associated with the key.
Returns:
dict: The updated dictionary.
"""
dictionary[key] = value
return dictionary
my_dict = {"name": "Max", "age": 25, "city": "Delhi"}
print("Original dictionary:", my_dict)
key_to_add = input("Enter the key to add: ")
value_to_add = input("Enter the value for the key: ")
updated_dict = add_key_value(my_dict, key_to_add, value_to_add)
print("Updated dictionary:", updated_dict)
#source code --> clcoding.com
0 Comments:
Post a Comment