Due: November 22, 2021
Points: 100
In the given examples, what you type is in red and the program prints what is in black. Your program output should look like the output in the examples, except that what you type won’t be in red. Also, the character ↵ means you end the line by pressing the return or enter key.
This assignment asks you to calculate the atomic weight of molecules.
The file “atomic_weights.txt” contains lines with three fields separated by tabs. The first field is the atomic weight, the second field is the symbol for the element, and the third field is the name of the element (which you can ignore for this problem).
We will proceed in stages, to make life easier. You should turn in only the final program, though.
A good way to check your program is to have it print out each atom’s symbol and the number that follows it, if any.
Hint: Element symbols are either 1 or 2 letters. The first letter is always capitalized; if there is a second letter, it is always lower case. So “HO” is a hydrogen atom (H) and an oxygen atom (O), and “Ho” is the symbol for holmium. Similarly, “SN” is a sulfur atom (S) and a nitrogen atom (N), and “Sn” is the symbol for tin. If no number follows an element’s name, treat it as 1.
Your output is to look like this:
Chemical composition? C2H5OH↵ The atomic weight of C2H5OH is 46.08 Chemical composition? H2O↵ The atomic weight of H2O is 18.02 Chemical composition? HO↵ The atomic weight of HO is 17.01 Chemical composition? Ho↵ The atomic weight of Ho is 164.93 Chemical composition? SN3↵ The atomic weight of SN3 is 74.1 Chemical composition? Sn3↵ The atomic weight of Sn3 is 356.13 Chemical composition? control-D
Call your program “compound.py”.
The output for the same input as in the main assignment would look like this:
Chemical composition? C2H5OH↵ The atomic weight of C2H5OH is 46.08 The elements are Carbon, Hydrogen, and Oxygen Chemical composition? H2O↵ The atomic weight of H2O is 18.02 The elements are Hydrogen and Oxygen Chemical composition? HO↵ The atomic weight of HO is 17.01 The elements are Hydrogen and Oxygen Chemical composition? Ho↵ The atomic weight of Ho is 164.93 The element is Holmium Chemical composition? SN3↵ The atomic weight of SN3 is 74.1 The elements are Nitrogen and Sulfur Chemical composition? Sn3↵ The atomic weight of Sn3 is 356.13 The element is Tin Chemical composition? control-DCall your program “longcompound.py”.
|
ECS 235A, Computer and Information Security Version of November 9, 2021 at 2:44PM
|
You can also obtain a PDF version of this. |