
Learning Objectives
In this challenge you will improve your string manipulation techniques as well as use Python to perform some basic mathematical calculations.
Did you know?
The molecular weight (mass) may be calculated from the molecular formula of the substance; it is the sum of the atomic weights of the atoms making up the molecule. The molecular mass is expressed in atomic mass unit (amu).
For example, water has the molecular formula H2O, indicating that there are two atoms of hydrogen and one atom of oxygen in a molecule of water.
| Atom | Atomic Mass | Quantity | Total Mass |
| H | 1.008 | 2 | 2.016 |
| O | 15.999 | 1 | 15.999 |
| H20 | 18.015 | ||
In the following script we use a Python dictionary called atomicMass to store the atomic mass of some of the main atoms (C, H, O…)
We then work out the molecular mass of water: H20.
Your Challenge
Adapt this script to get the program ask the end-user to enter a molecular formula of their choice.
Using string manipulation techniques your Python script will break down the formula entered by the end-user and calculate the total mass of the molecule.
Test your script with the following molecules:
| Molecule | Formula |
| Water | H2O |
| Carbon Dioxide | CO2 |
| Methane | CH4 |
| Butane | C4H10 |
| Carbonic Acid | H2CO3 |
| Acetone | CH3COCH3 |
| Lactose | C12H22O11 |
Challenge #2
Add more atoms to the atomMass dictionary as follows:
| Atom | Atomic Mass |
| Fe | 53.939 |
| Ag | 106.905 |
| Cu | 62.929 |
| Na | 22.989 |
| Cl | 34.968 |
Adapt your script so that it recognises when these atoms are used by the end-user when entering their molecular formula. This will be based on the use of uppercase & lowercase letters.
Test your script with the following molecules:
| Molecule | Formula |
| Sodium Chloride | NaCl |
| Iron Oxide | Fe2O3 |
| Copper Chloride Hydroxide | HOCuCl |

Solution...
The solution for this challenge is available to full members!Find out how to become a member:
➤ Members' Area

Converting Distances

Converting Temperatures
Converting Weights
Time Conversion
Have you ever seen a lightning flash or heard the thunder of lightning and wondered how close you were from the ligthning strike? Have you noticed that there is always a delay between the flash of light and the clap of thunder when a lightning occurs?





Shopping during the sales can sometimes be very confusing. With discounted prices at 10%, 20%, 50% or even 70%!
Degree Fahrenheit (°F) and Degree Celsius (°C) are the main two units to measure temperature.
The story tells us that long long ago the great Sultan of India loved to play games. As he started to get bored of the games that were present at the time he asked a wise man who lived in his kingdom to come up with a new game.
To the Sultan’s surprise, the wise man did not ask for any gold. Instead he only had one request: He asked just for a few grains of rice in the following manner: the sultan was to put a single grain of rice on the first chess square, two grains on the second square, four on the third square and carry on doubling this number on every consequent square to fill up all 64 squares of the chessboard.









The aim of this challenge is to draw a cube in 3D and to make it rotate on the screen.


Add more edges to the code given above to create a full house including a roof, a front door and a window.

