def learn_to_program():
return """
CS149 - Introduction to Programming
Department of Computer Science
Spring 2022
"""


Introduction

This activity will help you practice some of the concepts from this week and prepare for the homework problems.

Specifically you will practice:

• Converting user input to either a floating point number (float), like 3.14159, or an integer (int), like 314159.
• Using floating point division (/), integer division (//), and the remainder, or mod, operator (%) in the appropriate situations.
• Use f-strings to format decimal output.

Problem 1: Average Speed Calculator

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:

= Bike Race Average Speed Calculator = How many miles did you race? 18.66 How much time did that take you in hours, minutes, and seconds? Hours: 0 Minutes: 43 Seconds: 49 Your speed was 25.55 mph, which is 41.12 kph.

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 $$0+\frac{43}{60}+\frac{49}{3600}$$, so how can you do this for other numbers of hours, minutes, and seconds?

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.

Problem 2: Splitting feet into miles, furlongs, and feet.

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!).

Enter a total number of feet: 12345 12345 total feet is 2 mile(s), 2 furlong(s), and 465 feet.

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 $$660\times2 = 1320$$. And finally after we remove those 1320 from 1785 the remaining feet is 465.

Hint 4: Notice how close the words remaining and remainder are.