CS 141 - Spring 2018
Program 1: Measurement Converter
Assigned: Friday, January 19
Due: Thursday, January 25, 2018 by 11:55pm (on Moodle)
Description
Your program will prompt the user for an floating point value representing miles/hour. You will reprint that value along with the value converted to the following values:
- barleycorns/day
- furlongs/fortnight
- Mach number
- percentage of the speed of light
Here's a list of definitions and measures you may need:
- a barleycorn is a (very old) English measure of length. 1 meter is equal to 117.647 barleycorns
- a furlong is measure of distance, 220 yards
- a fortnight is a measure of time, 2 weeks
- the mach number is a measure of speed, the percentage of the speed of sound. Mach 1 is a speed equal to the speed of sound in air, which is 1130 feet/second. Mach 1.5 would be 1.5 times the speed of sound.
- PSL is a speed, the percentage of the speed of light in a vacuum. The speed of light is 299,792,458 meters/second.
- 1609.34 meters in a mile
- 1760 yards in a mile
- 5280 feet in a mile
What you need to do
Start a new Python program (in a separate window, not the Python shell). Put a comment
at the top with your name and a description of what the program does. Your comment should look like the standard program header shown here.
Write the program so that it does the following:
- Ask the user for the speed they wish to convert.
- Write code to convert the input into the 4 new measures of speed.
- Print out the original speed, the speed in barleycorn/day, furlongs/fortnight, mach number, and percentage of the speed of light.
Sample Interactions
What the computer displays (prints) is in regular text, what the user types is in bold, and what
the program is doing behind the scenes is in italics.
Test 1
(Program begins)
Please enter a speed in miles/hour: 1
Original speed in mph is: 1.0
Converted to barleycorn/day is: 4544016.55152
Converted to furlong/fortnight is: 2688.0
Converted to Mach number is: 0.0012979351032448377
Converted to percentage of speed of light: 1.4911612249060943e-09
(Program ends)
Test 2
(Program begins)
Please enter a speed in miles/hour: 800
The original speed is: 800.0
Converted to barleycorn/day is: 3635213241.216
Converted to furlong/fortnight is: 2150400.0
Converted to Mach number is: 1.0383480825958702
Converted to percentage of speed of light: 1.1929289799248755e-06
(Program ends)
Test 3
(Program begins)
Please enter a speed in miles/hour: 2.5
The original speed is: 2.5
Converted to barleycorn/day is: 11360041.3788
Converted to furlong/fortnight is: 6720.0
Converted to Mach number is: 0.003244837758112095
Converted to percentage of speed of light: 3.727903062265236e-09
(Program ends)
Your code does not need to follow this script verbatim, but all the mentioned functionality
should work as shown.
Hints
Work out some examples on paper first to determine how the math works in this problem.
Decide on what variables you need, what they represent in the problem, and what their data types should be.
Test your program on lots of examples and make sure the math checks out.
How to get started
Create a Python program named yourlastname_yourfirstname_prg1.py
Follow the instructions for commenting your code.
Submit your Python file on Moodle under Program 1.
Requirements
A good program will do all of the following:
Program file is named correctly.
Include the standard program header as a comment at the top of your program.
Prompt the user for the speed in miles/hour.
Calculate the correct conversions for each of the four units of measure.
Code is commented appropriately, is neatly and clearly formatted, and it includes proper use of 'white space'.
Challenge Problems
From time to time, I will offer "challenge problems" on assignments. These problems
are designed to have little (but some) impact on your grade whether you do them or not.
You should think of these problems as opportunities to work on something interesting and optional,
rather than a way to raise your grade through "extra credit."
Policy on challenge problems:
-
Challenge problems will typically allow you to get 2-5% of additional credit on an assignment, yet they
will typically be much more difficult than this credit amount suggests.
-
You should not attempt a challenge problem until you have finished the rest of an assignment.
- The tutors will not provide help on challenge problems. The instructor
will provide minimal assistance only, as these problems are optional and are designed
to encourage independent thought.
- Challenge problems may be less carefully specified and less carefully calibrated for how difficult or time-consuming they are.
Challenge problems for this assignment:
- Read how
to format strings in a print statement. Use the ideas to make each of your outputs include exactly 3 decimal places. Please include the original output (without rounding) for the Mach number and the percentage of speed of light.
Grading
Your program will be graded on correctness (whether your calculations are correct), as well as on coding style, which refers to choices you make when writing your code, such as good use of variable names, appropriate indentation, and comments (this is not an exhaustive list).
You will receive one bonus point for every complete day your program is turned in early, up to a maximum of five points. For instance, if your program is due on September 20 at 11:59pm, if you turn in your code on Moodle any time on September 19 from 12:00am through 11:59pm, you will receive one extra point on your project. Programs submitted on September 18 from 12:00am through 11:59pm will receive two points. This pattern continues for up to five points.