26-sept Functions

 26-sept Functions



LAB 1: Write a Python function greet_people(person_dict) that takes a dictionary as input where each key is a string (the person's name) and each value is an integer (the person's age). The function should print a message for each name and age in the dictionary in the format: Hello, {name}! You are {age} years old. onstraint The input dictionary will contain between 1and 10 entries. Each key (name) will be a string of length 1 to 50. Each value (age) will be an integer between 1and 100.

def greet_people(person_dict):
    for name, age in person_dict.items():
        print(f"Hello, {name}! You are {age} years old.")

LAB2: Write a Python function | calculate_area(length, width) that takes two inputs: two integers length and width, and returns the area of a | rectangle. | | Constraint | Both length and width will be positive | integers between 1and 1000. 

def calculate_area(length, width):
    return length * width

LAB 3: | Write a Python function | add_to_list(my list, item) that takes a list my_list and an item item. The | function should append the item to ~~ the list and return the updated list. onstraint | | The list will have a maximum length of | 10. | The item can be any valid Python data type. | |

def add_to_list(my_list, item):
    if len(my_list) < 10:
        my_list.append(item)
    return my_list 

LAB 4: Write a Python function is_in_set(my_set, item) that takes a set my _set and a variable item. The function should return True if the item exists in the set, otherwise return False. Constraint The set will contain up to 10 elements.

def is_in_set(my_set, item):
    return item in my_set