Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

physical_activity_data = [eqc244, Run, qqa640, run, Walk, cwq565, Jog, bike, zpr647, Bike, Walk, jvu311, walk, Workout, jnm492, Run, gcs800, Run, dvd058, jog, Bike, krg839, jog,

image text in transcribedimage text in transcribed

physical_activity_data = ["eqc244, Run", "qqa640, run, Walk", "cwq565, Jog, bike", "zpr647, Bike, Walk", "jvu311, walk, Workout", "jnm492, Run", "gcs800, Run", "dvd058, jog, Bike", "krg839, jog, Run", "fud109, bike, jog", "tcw030, Run, walk", "zvz690, walk, workout", "nst915, Walk", "rgi867, walk, Bike", "tpq635, bike", "gmp012, Jog, Bike", "aux704, walk, jog", "zsa777, walk, run, baseball", "ghw843, Walk", "lzn822, Bike", "gca402, bike, Walk", "klq707, Run, run", "xji280, Walk, Jog", "pca913, Bike, bike, Lift", "yum565, Walk, Jog", "ugm113, Run", "pba365, Walk", "cnd946, Jog", "idk407, Jog, Run", "auj402, jog, run"] 
Purpose: To practice using methods in the string object Practice with miking Loops and conditionals, and basic list manipulation. Degree of Difficulty: Moderate. Data collection generally refers to the process of gathering and measuring data about specific things. The measurements and results derived from data collection can be quite powerful and help researchers an swer important quesitons. Suppose we are helping a research lab at the U of S to analyze data they have collected about student's physical activity. Students were given a survey and asked "What physical activities do you do at least once a week for more than 10 minutes? Sadly. the records from the data collection came back in individual strings with comma separators. Ac- tivites also have inconsistent capitalization. So we will have to do some data cleaning before we analyze. An examble of some of the data can be seen below "eqc244. Run "qqa640 ru,Walk", "cwq565, Jog, bike". "2pr647, Bike, Walk" jvu311, valk, Workout"] We have provided you with a python file called a4q1 starter.py which defines a single list variable physical activity_data which includes all the collected data. Starting with this file, do the following: (a) The data isn't well formatted, so let's write a function to clean it up. Write a function calledclean data) that takes one parameter, a ist of activity records, and returns a list of strings (activities) each item in the original ll have to do the following . Use the string method split to generate a list of the activites. Here is an example showing the usage of split) an inals- ,dog , cat ,pig, goat, define a string variable #," argument new-list an inals.split(, ,') # split with print (nev list) ['dog,, ,cat, ,pig,, ,goat'] # ne -list nov refers to thi8 list . After splitting, use the string method oer) and strip) to make sure all activities are lower case and don't have leading or trailing spaces. . Add the clean activities to a new list that will be returned by your clean data) function. If you ran your clean_data) function on the example data from earlier, it should return a list like this ['run, run, alk Jog', 'bike, bike lk valkorkout'] Note that this new list does not include the NSIDs from the previous list We are not using them for our analysis so they can be ignored Be sure that you don't add them to the return list b) Write a function called count activites) that takes two parameters: a string activity containing a single activity, and a list of strings activity 1ist. The function must return the number of occurrences of activity in activity_1ist. If we passed in the list from above, and the argument 'run, the function would return 2 (c) Write a function called unique activities( with one parameter called activity_1ist which is a list of strings where each string is a single activity. The function should return a list of unique activities For example, if given the argument 'run run, 'jog', 'vorkout 'walk, 'run' 'alk'] then the expected retum value would be 'run'Jog workout valk '] The unique activites do not need to be returned in a specific order any order is fine so long as all the unique words are included. (d) Now to put all of our hard work together! In the main program (outside any function), call the function on the original list provided (physical activity data) to receive a new clean list. Now clean data call the unique activites) function with your new clean list. Finally. use for-loops to print out each activity and the number of times it occurs in the new clean list (call the function count activities) for each activity). Sample Output Your console output should look something like this: 12 students run at least once a week for more than 10 minutes 14 students walk at least once a week for more than 10 minutes 11 students jog at least once a week for more than 10 minutes 11 students bike at least once a week for more than 10 minutes 2 8tudent8 lorkout at lea8t once a week for more than 10 minutes students baseball at least once a veek for more than 10 minutes students 1lift at least once a veek for more than 10 minutes What to Hand In . A file called a4q1 py containing your finished program, as described above. Evaluation .4 marks for defining clean_data) that correctly uses split), stripO. and loerO: creating a list. removing spaces, and changing activities to lower case, and returning a list of activities. . 4 marks for defining count activities that correctly return the number of occurrences of a given .4 marks for defining unique_activites that correctly return the list of unique activites in a given list . 2 marks for printing out the number of occurrences of each activity. one sentence per activity. and activity in a given list of activites. of activites. each sentence on its own line

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Database Programming With Visual Basic.NET

Authors: Ying Bai

1st Edition

0521712351, 978-0521712354

More Books

Students also viewed these Databases questions

Question

Describe the nature of negative messages.

Answered: 1 week ago