Skip to content

Monday 9/4

Practice Questions

Coding Exercises

Miles, Furlongs, and FeetĀ¶

Write a program called feet_convert.py that requests a total number of feet and converts that value into miles, furlongs, and feet. One mile is 5280 feet, and one furlong is 660 feet.

Here is an example run of the program:

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 will need to use floor division and remainder (// and %).

Hint 3: Create a variable for the remaining feet. In the example above, the remaining feet is initially 12345. Once you figure out there are two full miles in 12345 feet (2 full miles is 10560 feet), then the remaining feet is 1785. How many full furlongs are in 1785 feet? Well, 2 again, since \(660 \times 2 = 1320\). And finally after we remove those 1320 from 1785, there are 465 feet remaining.

Splitting the Bill

Write a program named split.py that will determine the exact amount that each member of a dinner party should pay, including the tip. Note that the total amount of the bill, including the tip, should be rounded down to the nearest cent. Here is an example run of the program:

Amount: 21.60
Tip: 18.0
People: 3

Total: 25 dollar(s) and 48 cent(s)
Each person pays: 8 dollar(s) and 49 cent(s)
Fight over the remaining 1 cent(s)

Hint: This will be easier if you convert the total amount, after tip, to an integer number of pennies.

Studying

  • Resources:
  • Make sure you could finish any of the homework questions, from scratch, in ten minutes.