Coach Kyle has some top athletes who have the potential to q

Coach Kyle has some top athletes who have the potential to quality for Olympics. They have been training very had for the 5000 and 10000 meters running competition. The coach has been recording their timings for each 1000 meters. In the practice sessions, each athlete runs a distance in multiples of 1000 meters and the coach records their time for every 1000 meters.

Write a python program that reads a text file consisting of following data:

Alice 3:15, 2:45, 3:30, 2:27, 3:42

Bob 2:25, 3:15, 3:20, 2:57, 2:42, 3:27

Charlie 2:45, 3:25, 3:50, 2:27, 2:52, 3:12

David 2:15, 3:35, 3:10, 2:47

1. Use a function to read the data from the file

2. Implement the logic using Dictionary, List, and String.

3. Use maketrans and translate functions to replace commas with spaces

4. Use split function to split the timings into individual elements of a list

5. Perform necessary calculations to display min, max, and avg timings of each athlete

Expected output: Program should display the minimum and average time taken by each athlete and their name in a table format.

Solution

Coach Kyle is havaing the following data.

Alice 3:15, 2:45, 3:30, 2:27, 3:42

Bob 2:25, 3:15, 3:20, 2:57, 2:42, 3:27

Charlie 2:45, 3:25, 3:50, 2:27, 2:52, 3:12

David 2:15, 3:35, 3:10, 2:47

let us name it as Athlete.txt

now

1. Use a function to read the data from the file.

file.read( )

Alice 3:15, 2:45, 3:30, 2:27, 3:42

Bob 2:25, 3:15, 3:20, 2:57, 2:42, 3:27

Charlie 2:45, 3:25, 3:50, 2:27, 2:52, 3:12

file.readline( )

2.Implement the logic using Dictionary, List, and String:

One way to create a dictionary is to start with the empty dictionary and add key-value pairs. The empty dictionary is denoted with a pair of curly braces, {}:

Dictionary operations:

The del statement removes a key-value pair from a dictionary. For example, the following dictionary contains the names of various fruits and the number of each fruit in stock:

If someone buys all of the pears, we can remove the entry from the dictionary:

Or if we’re expecting more pears soon, we might just change the value associated with pears:

The len function also works on dictionaries; it returns the number of key-value pairs:

The in operator returns True if the key appears in the dictionary and False otherwise:

This operator can be very useful, since looking up a non-existant key in a dictionary causes a runtime error:

3.Use maketrans and translate functions to replace commas with spaces

4. Use split function to split the timings into individual elements of a list

split reverses by splitting a string into a multi-element list. Note that the delimiter (“,”) is stripped out completely; it does not appear in any of the elements of the returned list.

5. Perform necessary calculations to display min, max, and avg timings of each athlete

Coach Kyle has some top athletes who have the potential to quality for Olympics. They have been training very had for the 5000 and 10000 meters running competit
Coach Kyle has some top athletes who have the potential to quality for Olympics. They have been training very had for the 5000 and 10000 meters running competit

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site