Extra Credit 3

Due: Wednesday, November 13, 2024
Points: 50


Expand the program you wrote in question 1 to print the names of the elements in the compound, which are in the third field of the file “atomic_weights.txt”. If an element occurs twice, only list it once. Print them in sorted order, using proper grammar (so if there is one element, print “The element is”, and if there are more than one, print “The elements are”). Put commas after all but the last element names, and separate the ls two with “and”.

The output for the same input as in question 1 would look like this (input is in red).


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?  T↵
T: no such element
Chemical composition?  GpZx↵
Gp: no such element
Zx: no such element
Chemical composition?  GpHeZx↵
Gp: no such element
Zx: no such element
The valid element is Helium
Chemical composition? control-D

Call your program “longcompound.py”.


UC Davis sigil
Matt Bishop
Office: 2209 Watershed Sciences
Phone: +1 (530) 752-8060
Email: [email protected]
ECS 235A, Computer and Information Security
Version of November 4, 2024 at 11:17AM

You can also obtain a PDF version of this.

Valid HTML 4.01 Transitional Built with BBEdit Built on a Macintosh