Another beautiful day in this miserable world

3. Write a program that determines the molevular weight of a hydrocarbon based on the number of hydrogen, carbon, and oxygen atoms. You should use the following weights H = 1.0079 grams/mole C = 12.011 grams/mole O = 15.9994 grams/mole

(Bare with me here, I am a Comp Sci major not a Chem major :P)
#We must define the weight of a single gram/mole before we start our calulation
#Find out how many of each molecule is in the hydrocarbon
#Add together the weight times the amount of molecules and add them together


def main():
    print("This program determines the molecular weight of a hydrocarbon.")
    h = 1.0079
    c = 12.011
    o = 15.9994
    hnum = eval(input("How many hydrogen atoms are there? "))
    cnum = eval(input("How many carbon atoms are there? "))
    onum = eval(input("How many oxygen atoms are there? "))
    ans = (h*hnum) + (c*cnum) + (o*onum)
    print("The molecular weight of the hydrocarbon is ", ans)
main()

Comments on: "Python Programming: An Introduction to Computer Science by Zelle Chap 3 Ex 3" (1)

  1. […] This post was mentioned on Twitter by Python UK, Cori Smith. Cori Smith said: Determine the #molecular weight of a #hydrocarbon based on the #atoms http://bit.ly/ehFpX1 […]

Leave a comment