|
Due: 5:00 p.m. EST, Friday 28 October 2005.
Weight: 10% of course grade.
Submit your solutions by adding files to the directory ex03 in your Subversion repository. Please
remember to use svn update to get the ex03 directory that has been created for you,
rather than creating one of your own.
Question 1
A fresh batch of atoms has just been delivered to your nanotechnology lab, and you would like to figure out what you could make with them. You have a data file describing what goes in to each of the molecules you know how to make:
ammonia N 1 H 3 bleach Ca 1 O 2 Cl 2 ethanol C 2 H 6 O 1 lye Na 1 O 1 H 1 rust Fe 2 O 3 sand Si 1 O 2 vinegar C 2 H 4 O 2
Your job is to write a program called nanotech.py that reads a file in this format, and
figures out what can be made using the available atoms. How many
atoms are available of each kind is specified on the command line.
For example, if the program is run like this:
python nanotech.py compounds.dat N 2 Na 2 O 5 H 3
then the output should be:
ammonia lye
Each possibility is considered independently: we don't need to have enough hydrogen to make both ammonia and lye, for example---we're just interested in knowing if we have enough to make either.
Question 2
You are an overworked, underpaid lab administrator. It's your job
to figure out who has spent how long working on various projects. The
Python file lab.py defines three
dictionaries with information you'll need:
Person maps user IDs to names;Project maps project IDs to project names; andExperiment describes the experiments that have been
done for each project. The keys in this dictionary are project IDs;
the values are also dictionaries, with experiment names as keys, and
lists of dates, hours spent, and people involved as values.Write a Python program called hours.py
that imports these three dictionaries, and uses the data in them to
calculate how many hours each person has spent in the lab. The output
should look like this:
Kovalevskaya, Sofia: 4.5 Lomonosov, Mikhail: 23.0 Mendeleev, Dmitri: 7.0 Pavlov, Ivan: 5.5
Refer to the material on string formatting from the Dictionaries and Error Handling lecture to find out how to print numbers with exactly one digit after the decimal point.
Question 3
personal.txt.
Question 4
Make up a question that would be suitable for an assignment on
Python dictionaries (like this one). Put the exercise, your solution,
and a brief explanation of what you think students would learn from
doing the exercise, in ex03/dictionary-exercise.txt.