hw05.pdf - hw05_master 1 Homework 5 Applying Functions and Iteration Please complete this notebook by filling in the cells provided Before you begin

hw05.pdf - hw05_master 1 Homework 5 Applying Functions and...

This preview shows page 1 - 4 out of 10 pages.

hw05_master October 11, 2019 1 Homework 5: Applying Functions and Iteration Please complete this notebook by filling in the cells provided. Before you begin, execute the following cell to load the provided tests. Each time you start your server, you will need to execute this cell again to load the tests. Homework 5 is due Thursday, 10/3 at 11:59pm. You will receive an early submission bonus point if you turn in your final submission by Wednesday, 10/2 at 11:59pm. Late work will not be accepted as per the policies of this course. Throughout this homework and all future ones, please be sure to not re-assign variables throughout the notebook! For example, if you use max_temperature in your answer to one question, do not reassign it later on. Moreover, please be sure to only put your written answers in the provided cells. [ ]: # Don't change this cell; just run it. import numpy as np from datascience import * # These lines do some fancy plotting magic. import matplotlib % matplotlib inline import matplotlib.pyplot as plt plt . style . use( 'fivethirtyeight' ) import warnings warnings . simplefilter( 'ignore' , FutureWarning ) from client.api.notebook import Notebook ok = Notebook( 'hw05.ok' ) _ = ok . auth(inline = True ) 1.1 1. Counting Calories Burned from Exercise Suppose you’d like to count how many calories you’ve burned from exercise. You do 4 kinds of exercise: yoga, walking, sprinting, and volleyball. Every day in January, you record how many minutes of each kind of exercise you did that day. Those data are in a table called exercise.csv . 1
Image of page 1
[2]: exercise = Table . read_table( 'exercise.csv' ) exercise [2]: Day (in January) | yoga | walking | sprinting | volleyball 1 | 50 | 0 | 0 | 0 2 | 0 | 65 | 0 | 65 3 | 50 | 70 | 0 | 0 4 | 0 | 0 | 0 | 75 5 | 0 | 0 | 0 | 0 6 | 0 | 0 | 0 | 0 7 | 0 | 0 | 0 | 0 8 | 0 | 55 | 0 | 0 9 | 0 | 0 | 0 | 0 10 | 0 | 30 | 0 | 0 … (21 rows omitted) Different forms of exercise burn calories at different rates; for example, sprinting is more vigorous than walking. The table calories_per_minute contains estimates of the calories per minute burned by each activity. [3]: calories_per_minute = Table . read_table( 'calories_per_minute.csv' ) calories_per_minute [3]: Exercise | Calories per minute yoga | 6 walking | 5 sprinting | 20 volleyball | 4 Let’s start by finding the total number of minutes you spent exercising each day. Question 1. Write a function called compute_exercise_time . It should take one argument, a row from the exercise table that contains the day and amounts of time (in minutes) spent on yoga, walking, sprinting, and volleyball. It should return the total time spent exercising. Hint You can tbl.row(n) to get the n th row of a table. row.item("column_name") will allow you to select the element that corresponds to column_name in a particular row. BEGIN QUESTION name: q1_1 manual: false [4]: """ # BEGIN PROMPT def compute_exercise_time(exercise_row): ... """ ; # END PROMPT # BEGIN SOLUTION NO PROMPT def compute_exercise_time (exercise_row): yoga_time = exercise_row . item( "yoga" ) 2
Image of page 2
walking_time = exercise_row . item( "walking" ) sprinting_time = exercise_row . item( "sprinting" ) volleyball_time = exercise_row . item( "volleyball" ) return yoga_time + walking_time + sprinting_time + volleyball_time # END SOLUTION
Image of page 3
Image of page 4

You've reached the end of your free preview.

Want to read all 10 pages?

  • Fall '17
  • Playing card, Sprinting

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors