CIT 591 Assignment 1: Length conversions
Fall 2011, David Matuszek

# Purposes of this assignment

• To get you familiar with IDLE
• To get you started programming in Python

# General idea of the assignment

Write a program that will allow you to convert between various measures of length: English, metric, and a couple others.

• What number to convert,
• What unit of measure to convert from, and
• What unit of measure to convert to.

For example, you may want to convert 1.5 kilometers to inches.

Your program should support the following length measurements, and it should be able to convert any measurement into any other measurement--or to itself (for example, inches to inches).

• Metric: millimeters, centimeters, meters, kilometers (abbreviations: mm, cm, m, km)
• English: inch, foot, yard, mile (in, ft, yd, mi)
• Astronomical: light year, parsec (ly, pc)

That's from 10 measures, to 10 measures, or 100 possible conversions. You could write code for each of these 100 conversions (and a bad programmer might do exactly that). But with a little thought, you should realize that you can convert any from measure to one particular measure (I recommend meters), then convert that measure to the desired to measure. That's only 10 + 10, or 20 conversions--still a lot, but each conversion is a simple multiplication or division.

To save you some web searches: 1 foot is 0.3048 meters, 1 light year is 9,460,730,472,580.8 km, and 1 parsec is 3.262 light-years.

# Details

Your program should print out a short introductory message telling what it does, and what the various length abbreviations do. It should tell the user how to input conversion requests, and how to quit.

Here's an example conversion request:`   1.5 km in`    which means: convert 1.5 kilometers to inches.

You can read a line like this into a variable, say, request, with the command: ` request = input().split()`
(Don't worry if you don't understand this syntax yet.) If the user types in the above line, then the variable request will contain the list` ['1.5', 'km', 'in']`. You can refer to each of these parts as `request[0]`, `request[1]`, and `request[2]`.

Notice that the things in the list are strings, and there isn't much you can do with the string `'1.5'`--it needs to be changed into a "floating point" number. For this you can use the `float` function, like this: `number = float(request[0])`.

The user may want to perform multiple conversions, so don't quit the program after doing a single conversion. Instead, do conversions until the user enters the word `quit`. With the above input line, this will set `request` to the value` ['quit']`.

Each program is worth 100 points, unless otherwise specified. Grading will be based on correctness, style, and useability.

• Correctness: The program produces correct answers and does what the assignment says to do and does not crash.
• Because we haven't yet covered error recovery, it's okay in this assignment if the program crashes when given bad input.
• Style: The program has good names for variables and functions, proper spacing and indentation, good documentation, etc.
Submit your program, as a single `.py` file, to Sakai, by 6am Friday, September 16.