96%(23)22 out of 23 people found this document helpful
This preview shows page 1 - 4 out of 10 pages.
hw05_masterOctober 11, 20191Homework 5: Applying Functions and IterationPlease complete this notebook by filling in the cells provided.Before you begin, execute thefollowing cell to load the provided tests. Each time you start your server, you will need to executethis cell again to load the tests.Homework 5 is due Thursday, 10/3 at 11:59pm. You will receive an early submission bonus point ifyou turn in your final submission by Wednesday, 10/2 at 11:59pm. Late work will not be acceptedas per thepoliciesof this course.Throughout this homework and all future ones, please be sure to not re-assign variables throughoutthe notebook! For example, if you usemax_temperaturein your answer to one question, do notreassign it later on.Moreover, please be sure to only put your written answers in the providedcells.[ ]:# Don't change this cell; just run it.importnumpyasnpfromdatascienceimport*# These lines do some fancy plotting magic.importmatplotlib%matplotlibinlineimportmatplotlib.pyplotaspltplt.style.use('fivethirtyeight')importwarningswarnings.simplefilter('ignore',FutureWarning)fromclient.api.notebookimportNotebookok=Notebook('hw05.ok')_=ok.auth(inline=True)1.11. Counting Calories Burned from ExerciseSuppose you’d like to count how many calories you’ve burned from exercise.You do 4 kinds ofexercise: yoga, walking, sprinting, and volleyball.Every day in January, you record how manyminutes of each kind of exercise you did that day. Those data are in a table calledexercise.csv.1
:exercise=Table.read_table('exercise.csv')exercise:Day (in January) | yoga | walking | sprinting | volleyball1| 50| 0| 0| 02| 0| 65| 0| 653| 50| 70| 0| 04| 0| 0| 0| 755| 0| 0| 0| 06| 0| 0| 0| 07| 0| 0| 0| 08| 0| 55| 0| 09| 0| 0| 0| 010| 0| 30| 0| 0… (21 rows omitted)Different forms of exercise burn calories at different rates; for example, sprinting is more vigorousthan walking.The tablecalories_per_minutecontains estimates of the calories per minuteburned by each activity.:calories_per_minute=Table.read_table('calories_per_minute.csv')calories_per_minute:Exercise| Calories per minuteyoga| 6walking| 5sprinting| 20volleyball | 4Let’s start by finding the total number of minutes you spent exercising each day.Question 1.Write a function calledcompute_exercise_time. It should take one argument, arow from theexercisetable that contains the day and amounts of time (in minutes) spent onyoga, walking, sprinting, and volleyball. It should return the total time spent exercising.HintYou cantbl.row(n)to get thenth row of a table.row.item("column_name")will allow youto select the element that corresponds tocolumn_namein a particular row.BEGIN QUESTIONname: q1_1manual: false:""" # BEGIN PROMPTdef compute_exercise_time(exercise_row):...""";# END PROMPT# BEGIN SOLUTION NO PROMPTdefcompute_exercise_time(exercise_row):yoga_time=exercise_row.item("yoga")2
walking_time=exercise_row.item("walking")sprinting_time=exercise_row.item("sprinting")volleyball_time=exercise_row.item("volleyball")returnyoga_time+walking_time+sprinting_time+volleyball_time# END SOLUTION