Find an element in the periodic table.

★★★

In 1869 Russian chemist Dimitri Mendeleev started the development of the periodic table, arranging chemical elements by atomic mass. He predicted the discovery of other elements, and left spaces open in his periodic table for them.

Periodic table

Make

Write a program that allows the user to enter the symbol or name of an element. The program outputs the name of the element, the atomic weight and the group of elements it belongs to using the data in the table below.

Success Criteria

Remember to add a comment before a subprogram or selection statement to explain its purpose.

Create a subprogram called periodic_table that:

  1. Takes a parameter that is the symbol or name of an element in the periodic table. E.g. Li is Lithium.
  2. Ouputs the symbol of the element.
  3. Outputs the name of the element.
  4. Outputs the atomic weight of the element.
  5. Outputs the group the element belongs to.
  6. Ouputs “Element is not in the catalogue.” if the data is not in the program.
  7. Uses the data below for the subprogram:
Symbol Element Atomic weight Group
Li Lithium 6.94 Alkali metals
Na Sodium 22.99 Alkali metals
K Potassium 39.098 Alkali metals
F Fluorine 18.998 Halogens
Cl Chlorine 35.45 Halogens
Br Bromine 79.904 Halogens

Complete the main program so that:

  1. The user can input the symbol or name of an element.
  2. It calls the periodic_table subprogram to output the relevant data.

Typical inputs and outputs from the program would be:

Enter the symbol or name of an element: K
Symbol: K
Element: Potassium
Atomic weight: 39.098
Group: Alkali metals
Enter the symbol or name of an element: Chlorine
Symbol: Cl
Element: Chlorine
Atomic weight: 35.45
Group: Halogens
🆘 If you're really stuck, use this Parsons code sorting exercise
Complete program
# Periodic table program

# -------------------------
# Subprograms
# -------------------------
# Output data for an element
def periodic_table(element):
---
    match element:
---
        # Alkali metals:
        # Lithium.
        case "Li" | "Lithium":
---
            print("Symbol: Li")
            print("Element: Lithium")
            print("Atomic weight: 6.94")
            print("Group: Alkali metals")
---
        # Sodium.
        case "Na" | "Sodium":
---
            print("Symbol: Na")
            print("Element: Sodium")
            print("Atomic weight: 22.99")
            print("Group: Alkali metals")
---
        # Potassium.
        case "K" | "Potassium":
---
            print("Symbol: K")
            print("Element: Potassium")
            print("Atomic weight: 39.098")
            print("Group: Alkali metals")
---
            
        # Halogens:
        # Flourine.
        case "F" | "Fluorine":
---
            print("Symbol: F")
            print("Element: Fluorine")
            print("Atomic weight: 18.998")
            print("Group: Halogens")
---
        # Chlorine.
        case "Cl" | "Chlorine":
---
            print("Symbol: Cl")
            print("Element: Chlorine")
            print("Atomic weight: 35.45")
            print("Group: Halogens")
---
        # Bromine.
        case "Br" | "Bromine":
---
            print("Symbol: Br")
            print("Element: Bromine")
            print("Atomic weight: 79.904")
            print("Group: Halogens")
---
        # Any other element.
        case _:
---
            print("Element is not in the catalogue.")
---


# -------------------------
# Main program
# -------------------------
---
lookup = input("Enter the symbol or name of an element: ")
---
periodic_table(lookup)