163k views
4 votes
CAN ANYONE WHO IS GOOD AT PYTHON HELPPP TYSMMM
its an assgnn but im stuck with ittt

CAN ANYONE WHO IS GOOD AT PYTHON HELPPP TYSMMM its an assgnn but im stuck with ittt-example-1
CAN ANYONE WHO IS GOOD AT PYTHON HELPPP TYSMMM its an assgnn but im stuck with ittt-example-1
CAN ANYONE WHO IS GOOD AT PYTHON HELPPP TYSMMM its an assgnn but im stuck with ittt-example-3

1 Answer

1 vote

Answer:

alldata = []

with open('userdata.txt') as f:

for line in f:

userid, age, height = line.strip().split(',')

alldata.append((userid, int(age), int(height)))

# sort the data according to the User ID

sorted_data = sorted(alldata, key=lambda x: x[0])

# get the median User ID

median_userid = sorted_data[len(alldata)//2][0]

print('The median User ID is', median_userid)

# sort the data according to the Age

sorted_data = sorted(alldata, key=lambda x: x[1])

# get the median Age

median_age = sorted_data[len(alldata)//2][1]

print('The median Age is', median_age)

# sort the data according to the Height

sorted_data = sorted(alldata, key=lambda x: x[2])

# get the median Height

median_height = sorted_data[len(alldata)//2][2]

print('The median Height is', median_height)

User Tushar Aggarwal
by
7.7k points