Extra Credit 4

Due: Monday, March 4, 2019
Points: 25

  1. (25 points) 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? control-D↵

    Call your program “longcompound.py”.

UC Davis seal
Matt Bishop
Office: 2209 Watershed Science
Phone: +1 (530) 752-8060
Email: mabishop@ucdavis.edu
You can also obtain a PDF version of this.
Version of February 27, 2019 at 8:41PM