ASAP I need this code...
Design and implement in Python language, a program that calculates the molecular weight of a formula. Your program should accept a formula in whatever form you choose as input from the user, and should display the molecular weight for that formula. Your program must be able to handle formulas that:
The representation of data and the algorithm you choose for your implementation are entirely up to you. The interface for your program should clearly describe the expected input form so the user can interact effectively. Grading emphasis for this assignment is on correctness only -- inefficiency and inelegance may be commented on but will not adversely affect your grade except in extreme cases.
The periodic table of elements can be found in many sources, incuding numerous Web pages (e.g., www.chemicalelements.com/show/mass.html). A list of elements with their atomic weights is written as raw text below:
H 1.0080 He 4.0026 Li 6.9410 Be 9.0122 B 10.8100
C 12.0110 N 14.0067 O 15.9994 F 18.9984 Ne 20.1790
Na 22.9898 Mg 24.3050 Al 26.9815 Si 28.0860 P 30.9738
S 32.0600 Cl 35.4530 Ar 39.9480 K 39.1020 Ca 40.0800
Sc 44.9559 Ti 47.9000 V 50.9414 Cr 51.9960 Mn 54.9380
Fe 55.8470 Co 58.9332 Ni 58.7100 Cu 63.5460 Zn 65.3700
Ga 69.7200 Ge 72.5900 As 74.9216 Se 78.9600 Br 79.9040
Kr 83.8000 Rb 85.4678 Sr 87.6200 Y 88.9059 Zr 91.2200
Nb 92.9064 Mo 95.9400 Tc 98.9062 Ru 101.0700 Rh 102.9055
Pd 106.4000 Ag 107.8680 Cd 112.4000 In 114.8200 Sn 118.6900
Sb 121.7500 Te 127.6000 I 126.9045 Xe 131.3000 Cs 132.9055
Ba 137.3400 La 138.9055 Ce 140.1200 Pr 140.9077 Nd 144.2400
Pm 145.0000 Sm 150.4000 Eu 151.9600 Gd 157.2500 Tb 158.9254
Dy 162.5000 Ho 164.9303 Er 167.2600 Tm 168.9342 Yb 173.0400
Lu 174.9700 Hf 178.4900 Ta 180.9479 W 183.8500 Re 186.2000
Os 190.2000 Ir 192.2200 Pt 195.0900 Au 196.9665 Hg 200.5900
Tl 204.3700 Pb 207.2000 Bi 208.9806 Po 210.0000 At 210.0000
Rn 222.0000 Fr 223.0000 Ra 226.0254 Ac 227.0000 Th 232.0381
Pa 231.0359 U 238.02900 Np 237.0482 Pu 242.0000 Am 243.0000
Cm 247.0000 Bk 249.0000 Cf 251.0000 Es 254.0000 Fm 253.0000
Md 256.0000 No 256.0000 Lr 257.00
chemical_formula = input("Enter chemical formula: ")
atomicMass = {"He": 4.0026, "H" : 1.0080, "O" : 15.9994, "C" :
12.0110, "N" : 14.0067, "S" : 32.0600}
molecule = "He"
mass = atomicMass["He"]
print("\nMolecule: " + molecule + " - Mass: " + str(mass))
molecule= "H2O"
mass = atomicMass["H"] * 2 + atomicMass["O"]
print("\nMolecule: " + molecule + " - Mass: " + str(mass))
molecule= "H"
mass = atomicMass["H"]
print("\nMolecule: " + molecule + " - Mass: " + str(mass))
molecule= "H"
mass = atomicMass["H"]
print("\nMolecule: " + molecule + " - Mass: " + str(mass))
molecule= "O"
mass = atomicMass["O"]
print("\nMolecule: " + molecule + " - Mass: " + str(mass))
molecule = "(NH4)2SO4"
mass = atomicMass["NH*4"] * 2 + atomicMass["SO*4"]
print("\nMolecule: " + molecule + " - Mass: " +
str(mass))
Get Answers For Free
Most questions answered within 1 hours.