Question: data = [ [ Name , Age, City, Salary, Education ] , [ John Doe, 2 8 , New York, 7 5

data =[
["Name", "Age", "City", "Salary", "Education"],
["John Doe", 28, "New York", 75000, "Bachelor's"],
["Jane Smith", 35, "San Francisco", 90000, "Master's"],
["Mike Johnson", 22, "Los Angeles", 60000, "High School"],
["Emily Davis", 40, "Chicago", 110000,"PhD"],
["Chris Brown", 30, "Houston", 80000, "Bachelor's"],
["Sophia Miller", 25, "Miami", 65000, "Master's"],
["David Wilson", 32, "Denver", 95000, "Bachelor's"],
["Emma White", 27, "Seattle", 85000, "Master's"],
["Alex Carter", 45, "Dallas", 120000,"PhD"],
["Olivia Taylor", 29, "Phoenix", 70000, "Bachelor's"],
["Daniel Lee", 38, "Boston", 100000, "Master's"],
["Ava Brown", 33, "Atlanta", 88000, "Bachelor's"],
["Ryan Davis", 26, "San Diego", 72000, "Master's"],
["Grace Martinez", 31, "Austin", 98000,"PhD"],
["Ethan Adams", 36, "San Jose", 105000, "Bachelor's"],
["Mia Wilson", 23, "Portland", 68000, "Master's"],
["James Anderson", 42, "Philadelphia", 115000, "Bachelor's"],
["Lily Moore", 34, "Detroit", 92000, "Master's"],
["Michael Clark", 39, "Minneapolis", 110000,"PhD"]
]
# Function to Filter Data
def filter_data(criteria, value):
"""
Filters the dataset based on specified criteria and value.
Parameters:
criteria (str): The criteria to filter by ('name', 'gender', 'age', 'salary').
value: The specific value for the criteria.
Returns:
list: Filtered list of records.
"""
filtered_data =[]
for record in data:
if criteria == 'name' and record[0].lower()== value.lower():
filtered_data.append(record)
elif criteria == 'gender' and record[1].lower()== value.lower():
filtered_data.append(record)
elif criteria == 'age' and record[2]== value:
filtered_data.append(record)
elif criteria == 'salary' and record[3]== value:
filtered_data.append(record)
return filtered_data
# User Input for Criteria and Value
print("Please enter the criteria for filtering (options: 'name', 'city', 'age', 'salary'):")
criteria_input = input().lower() # Convert to lower case for consistent comparison
# Depending on the criteria, parse the value accordingly
if criteria_input in ['name', 'city', 'age', 'salary']:
print(f"Enter the value for {criteria_input}:")
if criteria_input in ['age', 'salary']:
value_input = int(input()) # Convert to integer for age and salary
else:
value_input = input() # Keep as string for name and gender
# Filter Data Based on User Input
filtered_result = filter_data(criteria_input, value_input)
# Function to calculate average salary
def calculate_average_salary(data):
total_salary = sum(record[4] for record in data)
average_salary = total_salary / len(data)
return average_salary
# Function to display data based on user input
def access_data(data, user_input):
try:
user_input = int(user_input)
if 1<= user_input <= len(data):
return data[user_input -1]
else:
return "Invalid input. Please enter a valid ID."Also, calculate the average salary displayed in the dataset. Also, use the loop in the program and use the method if the user wants to insert or delete data in the dataset.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!