


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Files to submit: hw2.py mph.py Functions to include in hw2.py:
**1. mph(milesran, time)
Remember all of the functions we used for HW1: raw_input(), float(), str() It might help to look at the comparison operators: http://docs.python.org/lib/comparisons.html Assume that the user will enter valid data (i.e. no negative or obscenely large numbers)
Your professor decides that for homework, everyone must go run a Pi Mile (http://dev.crc.gatech.edu/facilities/pimile.pdf) and time how long it takes to run the 3.14 miles. As you come in from your run and start to stretch, you decide to write a Python program to tell you just how fast you run and how many calories you’ve burned. The point of this assignment is to get you thinking about the differences between scripts and functions and between printing and returning.
We will start by writing a script to tell the user how many miles per hour he or she runs. DO NOT USE FUNCTIONS IN THIS PART. Prompt the user for how many miles he ran and how long it took to complete the run (in minutes). Do the appropriate calculations with these values and print out his speed in miles per hour. Example:
How many miles did you run? 3. How long was your run? (in minutes) 23 You run at 8.19 miles per hour! Save this script in a file called mph.py
Now we will write a more complicated version with functions.
Write a function, mph that takes in two parameters, milesran and time. Recall the syntax for setting up a function: def mph(milesran, time): This function should return a value for miles per hour, calculated using the parameters for the number of miles and time in minutes. You can test your function in the shell like so:
mph(3.14, 23)
mph(5.4, 55)
Now we will write a function to calculate and return how many calories the runner burned based on the number of miles ran. For every mile that you run, you burn 100 calories (no matter how fast you run). Use this fact to calculate how many calories you burn.
caloriesBurned(3.14)
And you burned 580.0 calories. What a speed demon you are! Put all of these functions in a file called hw2.py
Write an additional function, avgmiles(milesran, time) that calculates your average mile speed for example if you run 3 miles in 30 minutes, the function would return that you run 10 minute miles). Use this function in main() and print out the average mile speed with the rest of the output.
Be sure to name your files and functions exactly as indicated. READ THROUGH THE INSTRUCTIONS CAREFULLY. If you need help, be sure to come to office hours. Good Luck! Written by Beth York, Fall 2007