View the step-by-step solution to:

Question

I am given this code and I am suppose to complete it. Can you help me with it?


def

read_data(filename):

  rows = read_csv(filename)

Screenshot 2019-09-23 at 3.48.13 PM.pngScreenshot 2019-09-23 at 3.48.26 PM.png

Screenshot 2019-09-23 at 3.48.13 PM.png

IPPT Data
A different score is given whenever there is a timing difference of 10 seconds. From the
run.csv file, we observe that an 18-year-old who ran 08:30 (510 seconds) or faster would
The IPPT scoring criteria is provided to you in 3 different files:
get 50 points and one who ran between 08:31 (511 seconds) and 08:40 (520 seconds)
. Push-ups: pushup. csv
inclusive would get 49 points.
. Sit-ups: situp . csv
The data file shows the scores for the timing between 510 seconds to 1100 seconds.
. 2.4km Run: run. csv
Naturally, a timing less than 510 seconds would get 50 points, and a timing exceeding
1 100 seconds would get 0 points.
Push-up / Sit-up
Administravia
Push-ups and sit-ups in the IPPT are scored in terms of the number of repetitions that
a soldier can do in one minute. pushup. csv and situp. csv lists the scores that a soldier of
The following functions have been provided to you:
a certain age will obtain if they managed a particular number of repetitions.
The first row describes the number of repetitions, whereas the first column lists the age
. make_ippt_table(pushup_table, situp_table, run_table)
of the soldier.
. get_situp_table(ippt_table)
From the file situp. csv, we observe that an 18-year-old who did 10 sit-ups would get 0
. get_pushup_table (ippt_table)
points (green box), whereas a 40-year-old who did 10 sit-ups would get 3 points (yellow
. get_run_table(ippt_table)
box).
1 AGE/REP
10
Table Data Structure
boooo
oo
oo
oo
W N N N H H H O O O O O O O o O O O o O O O O O O
oo
To help you manipulate and access the data in a tabular fashion, we have provided an
implementation of a table data structure which would help you access the scores in the
IPPT table.
oo
oo
The functions that are provided for the table data structure:
o o o o o o o o o o o O O O O O O O
create_table(data, row_keys, col_keys)
. access_cell (table, row_key, col_key)
create_table takes in 3 parameters. The first parameter data is a tuple of tuples, which
contains the table of data. The second parameter row_keys is the tuple of keys associated
o o o o o o O O O O O O O
to each row, and the third parameter col_keys is the tuple of keys associated to each
column.
ooo .
W WW NN NH
W W W N
G U UI UI A A A W W W N N NT
As an example, consider the following table:
S/N
Name
Gender Age
Course
A CON -
Wai Hon
M
23
Business Analytics
Yang Shun
M
25
Computer Science
Xiangxin
18
Computer Science
Soedar
M
25
Computer Science
2.4km Run
The following code sample illustrates how to represent the above data in Python using
our own table data structure:
The 2.4km run in the IPPT is scored based on the timing a soldier takes to complete a
2.4km run. To simplify things, we will represent the time of the run in seconds. run. csv
user_data = (("Wai Hon", "M", 23, "
"Business Analytics"),
lists the score that a soldier of a certain age will obtain if they complete the run under a
( "Yang Shun", "M", 25, "Computer Science"),
particular timing
("Xiangxin",
"F ", 18, "Computer Science"),
( "Soedar", "M", 25, "Computer Science"))
The first row describes the time in seconds, while the first column lists the age of the
soldier.
user_table = create_table (user_data ,

Screenshot 2019-09-23 at 3.48.26 PM.png

(1, 2, 3, 4),
( "Name", "Gender", "Age", "Course"))
access_cell, is a general accessor which would retrieve a particular cell from a table
given a row_key and a column_key. Compare the returned value of the execution of the
access_cell functions below with the table above.
access_cell (user_table , 1, "Course")
# Business Analytics
access_cell (user_table , 2, "Age")
# 25
access_cell (user_table , 3, "Name")
# Xiangxin
access_cell (user_table , 4, "Gender")
# M
Task 1: Read Data (4 marks)
Implement read_data, a function that would read the input data file, and return a table
of scores for a particular station.
situp_table = read_data ("situp . csv")
pushup_table = read_data ("pushup . csv")
run_table = read_data ("run . csv")
# Sit-up score of a 24-year-old who did 10 sit-ups.
access_cell (situp_table , 24, 10)
# 0
# Push-up score of a 18-year-old who did 30 push-ups.
access_cell (pushup_table , 18, 30)
# 16
# Run score of a 30-year-old who ran 12 minutes (720 seconds)
access_cell (run_table , 30, 720)
# 36
# Since our run . csv file does not have data for 725 seconds, we should
# get None if we try to access that cell.
access_cell (run_table , 30, 725)
# None

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes