Write a function that takes a list of tuples, each containing a name and age, and returns a list of names of people who are above 18.
def names_above_18(people):
return [name for name, age in people if age > 18]
# Example usage:
people = [("Alice", 17), ("Bob", 20), ("Charlie", 19)]
adults = names_above_18(people)
print(adults) # Output: ['Bob', 'Charlie']
Create a function that accepts a tuple of numbers and returns a new tuple with the numbers sorted in ascending order.
Given a list of dictionaries representing students (each dictionary containing keys like name, age, and grades), write a function to calculate the average grade of all students.
Python program that takes a list of tuples, each containing a name and age, and returns a list of names of people who are above 18, without using a function call.
“`python
# List of tuples with names and ages
people = [(“Alice”, 17), (“Bob”, 20), (“Charlie”, 16), (“Diana”, 22), (“Edward”, 19)]
# The journey to find those who have crossed the threshold of adulthood
adults = []
# The moment of truth – checking each person’s age
for person in people:
name, age = person
if age > 18:
adults.append(name)
# Celebrating the outcome – those who are above 18!
print(“These are the legends, the ones who stand tall above 18: “, adults)
“`
Leave a Reply to codinn Cancel reply