Data geeks log their daily activities for no good reasons. In this problem, you are to process data in a logbook. The logbook is given to you as a list of strings. These are the lines from the logbook. Our goal is to derive this person's average jogging speed (ignoring data about all other activities). The author logged data into her book carefully following a specific format. Hence, your input looks similar to the following example: log_book = [ "cycling;time:1,49;distance:2", "jogging;time:40,11;distance:6", "swimming; time:1,49;distance:1.2", "jogging; time:36,25;distance:5.3", "hiking; time:106,01;distance:8.29" There can be as many lines (entries) as the logbook may contain. But each line always contains three pieces of information: (1) the type of activity; (2) the duration of that activity (time in minutes); and (3) the distance involved in that activity (in km).

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
Data geeks log their daily activities for no good reasons. In this problem, you are to process data in a
logbook. The logbook is given to you as a list of strings. These are the lines from the logbook. Our goal
is to derive this person's average jogging speed (ignoring data about all other activities).
The author logged data into her book carefully following a specific format. Hence, your input looks
similar to the following example:
log_book = [
"cycling;time:1,49;distance:2",
"jogging;time:40,11;distance:6",
"swimming; time:1,49;distance:1.2",
"jogging; time:36,25;distance:5.3",
"hiking; time:106,01;distance:8.29"
There can be as many lines (entries) as the logbook may contain. But each line always contains three
pieces of information:
(1) the type of activity;
(2) the duration of that activity (time in minutes); and
(3) the distance involved in that activity (in km).
These three pieces are semicolon(;)-separated, and there will not be extra spaces anywhere. Therefore,
for example, entry 0 in the example shows a cycling activity that lasted for 1 minute and 49 seconds
involving 2 km of distance.
The author always uses a comma (, ) to separate minutes from seconds. The seconds will always have
2 digits. For the distance component, she uses a dot (.) between the integral and the fraction parts.
This dot is omitted if there is only the integral part. The jogging activity-the only activity relevant to
us–is every line where the activity field is exactly "jogging". This means, if the activity field is, for
example, 'joggingandsprinting', it will not be counted.
YOUR TASK: It helps to break this big task down into smaller functions, representing different logical
units. Your main goal is to write a function jogging_average(activities: list[str]) -> float
that takes a list of strings similar to the example above and returns a floating-point number that equals
the author's average jogging speed in m/sec (meter per second)'. To be very precise, your answer only
has to be correct up to ±0.0001. We promise also that there will be at least one jogging entry with a
positive duration and distance.
Transcribed Image Text:Data geeks log their daily activities for no good reasons. In this problem, you are to process data in a logbook. The logbook is given to you as a list of strings. These are the lines from the logbook. Our goal is to derive this person's average jogging speed (ignoring data about all other activities). The author logged data into her book carefully following a specific format. Hence, your input looks similar to the following example: log_book = [ "cycling;time:1,49;distance:2", "jogging;time:40,11;distance:6", "swimming; time:1,49;distance:1.2", "jogging; time:36,25;distance:5.3", "hiking; time:106,01;distance:8.29" There can be as many lines (entries) as the logbook may contain. But each line always contains three pieces of information: (1) the type of activity; (2) the duration of that activity (time in minutes); and (3) the distance involved in that activity (in km). These three pieces are semicolon(;)-separated, and there will not be extra spaces anywhere. Therefore, for example, entry 0 in the example shows a cycling activity that lasted for 1 minute and 49 seconds involving 2 km of distance. The author always uses a comma (, ) to separate minutes from seconds. The seconds will always have 2 digits. For the distance component, she uses a dot (.) between the integral and the fraction parts. This dot is omitted if there is only the integral part. The jogging activity-the only activity relevant to us–is every line where the activity field is exactly "jogging". This means, if the activity field is, for example, 'joggingandsprinting', it will not be counted. YOUR TASK: It helps to break this big task down into smaller functions, representing different logical units. Your main goal is to write a function jogging_average(activities: list[str]) -> float that takes a list of strings similar to the example above and returns a floating-point number that equals the author's average jogging speed in m/sec (meter per second)'. To be very precise, your answer only has to be correct up to ±0.0001. We promise also that there will be at least one jogging entry with a positive duration and distance.
the author's average jogging speed in m/sec (meter per second)'. To be very precise, your answer only
has to be correct up to +0.0001. We promise also that there will be at least one jogging entry with a
positive duration and distance.
Now, to implement this function, you may wish to implement the following helper functions:
• a function parse_time(line: str) -> int that takes a string (a line in the logbook) and re-
turns the duration mentioned in this line (in seconds). For example,
IWe know this is an usual unit for jogging speed, but we hope it helps everyone's sanity.
parse_time('jogging;time:40,11;distance:6')
should return 60 × 40+ 11 = 2411.
• a function parse_dist(line: str) -> float that takes a string (a line in the logbook) and
returns the distance mentioned in this line (in km). For example,
parse_dist('jogging;time:40,11;distance:7.1')
should return 7.1.
EXAMPLES: Running jogging_average on the input described above, we should get 2.4586597.
This is because there were two jogging activities:
• "jogging; time:40,11;distance:6", which translates to 2411 seconds and 6 km; and
"jogging; time:36,25;distance:5.3", which translates to 2185 seconds and 5.3 km.
Therefore, the author has covered a distance of 11.3 km-that is, 11300.0 meters, in 2411+2185 = 4596
seconds. Hence, the average jogging speed is
Distance [m]_ 11300.0 [m]
Time [s]
Avg. Speed =
2.4586597 [m/s],
4596 [s]
so the function returns the floating-point number 2.4586597.
Transcribed Image Text:the author's average jogging speed in m/sec (meter per second)'. To be very precise, your answer only has to be correct up to +0.0001. We promise also that there will be at least one jogging entry with a positive duration and distance. Now, to implement this function, you may wish to implement the following helper functions: • a function parse_time(line: str) -> int that takes a string (a line in the logbook) and re- turns the duration mentioned in this line (in seconds). For example, IWe know this is an usual unit for jogging speed, but we hope it helps everyone's sanity. parse_time('jogging;time:40,11;distance:6') should return 60 × 40+ 11 = 2411. • a function parse_dist(line: str) -> float that takes a string (a line in the logbook) and returns the distance mentioned in this line (in km). For example, parse_dist('jogging;time:40,11;distance:7.1') should return 7.1. EXAMPLES: Running jogging_average on the input described above, we should get 2.4586597. This is because there were two jogging activities: • "jogging; time:40,11;distance:6", which translates to 2411 seconds and 6 km; and "jogging; time:36,25;distance:5.3", which translates to 2185 seconds and 5.3 km. Therefore, the author has covered a distance of 11.3 km-that is, 11300.0 meters, in 2411+2185 = 4596 seconds. Hence, the average jogging speed is Distance [m]_ 11300.0 [m] Time [s] Avg. Speed = 2.4586597 [m/s], 4596 [s] so the function returns the floating-point number 2.4586597.
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY