Get the details of an element by Atomic Number using Python
Last Updated :
31 Oct, 2023
In this article, we will learn how to get the details of the elements by inputting the atomic number using the Python module. Chemistry’s foundational tool, the periodic table of elements provides a structured and ordered perspective of the constituent parts of matter. Each of the elements in this table has distinct qualities and traits that have captivated scientists for ages.
Get the details of an element by Atomic Number
Requirements:
We’ll explore the “periodictable” module in this tutorial by delving into the chemical and programming worlds of Python. This module offers a simple way to obtain important information on chemical elements, including atomic numbers and symbols, atomic masses, and more, even though it is not a part of the standard Python library.
Periodictable:
The ‘periodictable’ module is a Python package designed to make it easier to retrieve important chemical element data. It provides a method that is both structured and simple to use for retrieving data on all known chemical elements, including their atomic weights, densities, names, symbols, and numbers. This package also offers a periodic table of the elements together with support for mass and x-ray/neutron scattering data.
To install the package run the below command in the terminal window:
pip install periodictable
Code:
Python3
import periodictable
try :
Atomic_no = int ( input ( "Enter the Atomic Number of the Element: " ))
element = periodictable.elements[Atomic_no]
print ( "Atomic Number:" , element.number)
print ( "Symbol:" , element.symbol)
print ( "Name:" , element.name)
print ( "Atomic Mass:" , element.mass)
print ( "Density:" , element.density)
except ValueError:
print ( "Please enter a valid atomic number as an integer." )
except KeyError:
print ( "The entered atomic number does not exist in the periodic table." )
|
Working:
1) Imports the ‘periodictable’ module, which provides data about chemical elements.
2) Uses a try-except block to handles the errors during user input and prompts the user to input the atomic number of an element.
3) Converts the user’s input into an integer, representing the atomic number and retrieves information about the element with the specified atomic number using the module’s dictionary.
4) Prints various properties of the element, including its atomic number, symbol, name, atomic mass, and density.
5) Handles the errors, if the user doesn’t enter a valid integer, it prints a message asking for a valid atomic number or if the entered atomic number doesn’t correspond to any known element, it prints a message indicating that the element doesn’t exist in the periodic table.
Output:
Example 1: Atomic Number-11 (Sodium)
Output: Sodium
Example 2: Atomic Numebr -17(Chlorine)
Output: Chlorine
Example 3: Atomic Number -13(Aluminium)
Output: Aluminium
Share your thoughts in the comments
Please Login to comment...