def learn_to_program(): return """ CS149 - Introduction to Programming Department of Computer Science James Madison University Spring 2022 """
This activity will help you practice some of the concepts from this week and prepare for the homework problems.
Specifically you will practice:
For this problem you will write a program named bike_speed.py
that
asks the user for the length of a bike race in miles (entered as a
floating point number) and their finishing time for the race in hours,
minutes, and seconds and then output their average speed in both miles
per hour and kilometers per hour. (1 mile = 1.60934 kilometers). When
you output the speed you should show exactly 2 digits past the decimal
place.
Here is an example run of the program:
Hint 1: Figure out how to calculate it by hand on paper before you try to code anything. You can’t code what you can’t solve with a pen and paper.
Hint 2: You’ll want to get your time into one unit. Dealing with 3
separate units is not good for computation. At the end of the day, we
need to do distance / time in hours to solve the problem, so what is
the total time in hours and how do you calculate it? Note that 0
hours, 43 minutes, and 49 seconds is ~0.7303 hours. How do you
calculate this? I calculated it by
Hint 3: Section 2.4 in the reading introduces f-strings for formatting output to a number of decimal places. If you don’t remember how to do it, get it working with any number of decimal places and then fix it when you’ve got the rest working.
For this problem you are going to write a program called
feet_conversion.py
to use integer division and remainders to take a
total number of feet and split it into miles, furlongs, and feet. 1
mile is 5280 feet and 1 furlong is 660 feet (it’s some old English
measure nobody uses anymore, but let’s do it anyways!).
Hint 1: Figure out how to solve the problem yourself by hand on paper. You can’t code something you don’t know how to solve.
Hint 2: You need to use integer division // and the mod/remainder % operators.
Hint 3: You probably want a variable for the remaining feet. For
instance, before you’ve figured out the answer above, the remaining
feet is 12345. But once you figure out that there are two full miles
in 12345 feet (2 full miles is 10560 feet), then the remaining feet
you have to deal with in your calculation is 1785 feet. Then how many
full furlongs are in 1785 feet? Well, 2 again, since
Hint 4: Notice how close the words remaining and remainder are.