.. _homework5: Homework 5 (Due 6 pm, Wednesday, 11/09/2016) ########################################################################## Please submit your homework to your git repo by **6 pm, Wednesday, 11/09/2016**. 1. Download a file :download:`words.txt <./hw5/words.txt>` and study the example code below: .. literalinclude:: ./hw5/words_example.py :language: python :linenos: (a) Write a function which reads the first N many words from the file ``words.txt`` and builds a list with one element per word. N is a user input number (Hint: use the ``append`` method). In addition, how can you read in ALL of the words and use them build a list without knowing the total number of words in ``words.txt``? (b) Write a function which reads the first N many words from ``words.txt`` and stores them as keys in a dictionary. It doesn't matter what the values are. Use the ``in`` operator to check whether a user input string (e.g., ``aa``) is in the dictionary. Again, please do the same to build a dictionary that includes ALL the words as keys in ``words.txt``. 2. You are going to implement a Python routine that converts a length in a given unit system into others systems. The unit systems we are considering include: * meter, yard, mile, inch, and foot. The conversion factors are given as:: 1 meter = 0.000621 miles = 39.370079 inches = 3.28084 feet = 1.093613 yards The routine takes two inputs from users: 1. a numerical value of length, 2. a unit system of the length input Your routine should convert a length in a requested unit system into the other systems. Please make sure that your implementation should be general enough to take any unit system as an input, and convert it to the rest. For instance, the output needs to look like:: $ python yourRoutine.py Please input a length (number only): 10 Please type a unit system (meter, mile, inch, foot, yard): yard ['0.00567842554907 mile', '360.000100584 inch', '30.000009144 foot', '9.14400249448 meter'] $ python yourRoutine.py Please input a length (number only): 159 Please type a unit system (meter, mile, inch, foot, yard): yard ['0.0902869662303 mile', '5724.00159929 inch', '477.00014539 foot', '145.389639662 meter'] and similarly for the rest unit systems. In addition, please extend your routine to convert a requested length into the SI multiples for meter: * nanometer (nm), micrometer (um), millimiter (mm), centimeter (cm), meter (m), kilimeter (km). The conversion factors are given by:: 1 meter = 10^9 nm = 10^6 um = 10^3 mm = 10^2 cm = 10^(-3) km The full output now looks like, for the first case:: Please input a length (number only): 10 Please type a unit system (meter, mile, inch, foot, yard): yard ['0.00567842554907 mile', '360.000100584 inch', '30.000009144 foot', '9.14400249448 meter'] ['9144002494.48 nm', '9144002.49448 um', '9144.00249448 mm', '914.400249448 cm', '0.00914400249448 km'] and for the second case:: Please input a length (number only): 159 Please type a unit system (meter, mile, inch, foot, yard): yard ['0.0902869662303 mile', '5724.00159929 inch', '477.00014539 foot', '145.389639662 meter'] ['1.45389639662e+11 nm', '145389639.662 um', '145389.639662 mm', '14538.9639662 cm', '0.145389639662 km'] .. note:: It is absolutely up to you how to output your result, in other words, you don't need to follow the output style shown in the above. However, your converted numbers should be correct, followed by the corresponding unit systems (e.g., ``477.00014539 foot``, etc.). .. note:: Your entire implementation, including inline comments and empty lines, is going to be ~ 100 lines or so. If you end up with writing, say, 500 lines of code, something is not quite right... 3. Write a short code document (3-page limit) using LaTeX to describe your implementation of Problem 2. You should include the following items in your report: * descriptions of your function implementations (e.g., inputs, outputs, usages of lists, dictionaries, etc...) * a couple of examples about how to run your routine (two or three test cases that can be reproducible by the instructor and TA) * any comments you think important If you need to learn how to write a LaTeX document, please take a look at `AMS 200 on LaTeX `_