Question: data = [ [ Name , Age, City, Salary, Education ] , [ John Doe, 2 8 , New York, 7 5
data
Name "Age", "City", "Salary", "Education"
John Doe", "New York", "Bachelor's"
Jane Smith", "San Francisco", "Master's"
Mike Johnson", "Los Angeles", "High School"
Emily Davis", "Chicago", PhD
Chris Brown", "Houston", "Bachelor's"
Sophia Miller", "Miami", "Master's"
David Wilson", "Denver", "Bachelor's"
Emma White", "Seattle", "Master's"
Alex Carter", "Dallas", PhD
Olivia Taylor", "Phoenix", "Bachelor's"
Daniel Lee", "Boston", "Master's"
Ava Brown", "Atlanta", "Bachelor's"
Ryan Davis", "San Diego", "Master's"
Grace Martinez", "Austin", PhD
Ethan Adams", "San Jose", "Bachelor's"
Mia Wilson", "Portland", "Master's"
James Anderson", "Philadelphia", "Bachelor's"
Lily Moore", "Detroit", "Master's"
Michael Clark", "Minneapolis", PhD
# Function to Filter Data
def filterdatacriteria 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.
filtereddata
for record in data:
if criteria 'name' and recordlower value.lower:
filtereddata.appendrecord
elif criteria 'gender' and recordlower value.lower:
filtereddata.appendrecord
elif criteria 'age' and record value:
filtereddata.appendrecord
elif criteria 'salary' and record value:
filtereddata.appendrecord
return filtereddata
# User Input for Criteria and Value
printPlease enter the criteria for filtering options: 'name', 'city', 'age', 'salary':
criteriainput inputlower # Convert to lower case for consistent comparison
# Depending on the criteria, parse the value accordingly
if criteriainput in name 'city', 'age', 'salary':
printfEnter the value for criteriainput:
if criteriainput in age 'salary':
valueinput intinput # Convert to integer for age and salary
else:
valueinput input # Keep as string for name and gender
# Filter Data Based on User Input
filteredresult filterdatacriteriainput, valueinput
# Function to calculate average salary
def calculateaveragesalarydata:
totalsalary sumrecord for record in data
averagesalary totalsalary lendata
return averagesalary
# Function to display data based on user input
def accessdatadata userinput:
try:
userinput intuserinput
if userinput lendata:
return datauserinput
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
