Electronic Configuration Project

Fun with Chemistry: Electronic Configuration Project using Python for Class 11 CS

In this post, we’ll explore a simple Python program that helps you find the electronic configuration of elements using their atomic number or symbol. It’s perfect for learning Python basics like functions, loops, and error handling while diving into a cool chemistry topic. Let’s break it down step by step in easy language!

 

What Does This Program Do?

This Python program lets you:

  • Enter an element’s atomic number (like 1 for Hydrogen) or symbol (like “H”).
  • Get its electronic configuration (how electrons are arranged in its orbits).
  • Try again if you want or stop when you’re done.

 

The Source Code

# Import sleep function
from time import sleep

# Do in 'try' and except not to get error
try:
    # Print heading
    print(" --- :Chemistry with Python = :) :--")
    
    # Global indentifiers used in program
    AtNo = ""
    atno = ""

    # define function to get data from user
    def get_input_at_no():
        global AtNo, atno
        atno = int(
            input("\n \t  Enter Atomic number of element..\n \t  ==================================\n\n\t>>>   "))
        print('')
        AtNo = atno
        sleep(5)


    # define function to get data from user


    def get_input_at_sym():
        global AtNo, atno
        symb = ['H', "He", 'Li', "Be", "B", "C", "N", "O", "F", 'Ne', 'Na', 'Mg', 'Al', 'Si', 'P', 'S', 'Cl', 'Ar', 'K',
                'Ca', 'Sc', 'Ti', 'V',
                'Cr', 'Mn', 'Fe', 'Co', 'Ni', 'Cu', 'Zn', 'Ga', 'Ge', 'As', 'Se', 'Br', 'Kr', 'Rb', 'Sr', 'Y', 'Zr',
                'Nb', 'Mo', 'Tc', 'Ru',
                'Rh', 'Pd', 'Ag', 'Cd', 'In', 'Sn', 'Sb', 'Te', 'I', 'Xe', 'Cs', 'Ba', 'La', 'Ce', 'Pr', 'Nd', 'Pm',
                'Sm', 'Eu', 'Gd', 'Tb',
                'Dy', 'Ho', 'Er', 'Tm', 'Yb', 'Lu', 'Hf', 'Ta', 'W', 'Re', 'Os', 'Ir', 'Pt', 'Au', 'Hg', 'Tl', 'Pb',
                'Bi', 'Po', 'At', 'Rn',
                'Fr', 'Ra', 'Ac', 'Th', 'Pa', 'U', 'Np', 'Pu', 'Am', 'Cm', 'Bk', 'Cf', 'Es', 'Fm', 'Md', 'No', 'Lr',
                'Rf', 'Ha', 'Unh', 'Ns',
                'Hs', 'Mt', 'Uun', 'Uuu', 'Uub', 'Uut', 'Uuq', 'Uup', 'UUh', 'Uus', "Uuo"]
        symbo = input("\n \t  Enter Atomic symbol of element..\n \t  =================================\n\n\t>>>   ")
        print('')
        if len(symbo) == 1:
            symbo = symbo.capitalize()
        elif len(symbo) == 2:
            symbo = symbo.__getitem__(0).capitalize() + symbo.__getitem__(1).lower()
        elif len(symbo) == 3:
            symbo = symbo.__getitem__(0).capitalize() + symbo.__getitem__(1).lower() + symbo.__getitem__(2).lower()

        AtNo = int(symb.index(symbo)) + 1
        atno = AtNo
        sleep(5)


    # define function for 3d electronic config


    def ele_con():
        global AtNo
        orb = ['1s', '2s', '2p', '3s', '3p', '4s', '3d', '4p', '5s', '4d', '5p', '6s', '4f', '5d', '6p', '7s', '5f',
               '6d', '7p']
        if AtNo == 24:
            print(' 1s 2', '2s 2', '2p 6', '3s 2', '3p 6', '3d 5', '4s 1', sep=' , ')
        elif AtNo == 29:
            print(' 1s 2', '2s 2', '2p 6', '3s 2', '3p 6', '3d 10', '4s 1', sep=' , ')
        elif AtNo == 41:
            print(' 1s 2', '2s 2', '2p 6', '3s 2', '3p 6', '3d 10', '4s 2', '4p 6', '4d 4', '5s 1', sep=' , ')
        elif AtNo == 42:
            print(' 1s 2', '2s 2', '2p 6', '3s 2', '3p 6', '3d 10', '4s 2', '4p 6',
                  '4d 5', '5s 1', sep=' , ')
        elif AtNo == 44:
            print(' 1s 2', '2s 2', '2p 6', '3s 2', '3p 6', '3d 10', '4s 2', '4p 6',
                  '4d 7', '5s 1', sep=' , ')
        elif AtNo == 45:
            print(' 1s 2', '2s 2', '2p 6', '3s 2', '3p 6', '3d 10', '4s 2', '4p 6',
                  '4d 8', '5s 1', sep=' , ')
        elif AtNo == 46:
            print(' 1s 2', '2s 2', '2p 6', '3s 2', '3p 6', '3d 10', '4s 2', '4p 6',
                  '4d 10', '5s 0', sep=' , ')
        elif AtNo == 47:
            print(' 1s 2\n', '2s 2\n', '2p 6\n', '3s 2\n', '3p 6\n', '3d 10\n', '4s 2\n', '4p 6\n',
                  '4d 10\n', '5s 1', sep=' , ')
        elif AtNo == 57:
            print(' 1s 2', '2s 2', '2p 6', '3s 2', '3p 6', '3d 10', '4s 2', '4p 6', '4d 10', '5s 2',
                  '5p 6',
                  '5d 1', '6s 2', sep=' , ')
        elif AtNo == 58:
            print(' 1s 2', '2s 2', '2p 6', '3s 2', '3p 6', '3d 10', '4s 2', '4p 6', '4d 10', '5s 2',
                  '5p 6',
                  '4f 1', '5d 1', '6s 2', sep=' , ')
        elif AtNo == 64:
            print(' 1s 2', '2s 2', '2p 6', '3s 2', '3p 6', '3d 10', '4s 2', '4p 6', '4d 10', '5s 2',
                  '5p 6',
                  '4f 7', '5d 1', '6s 2', sep=' , ')
        elif AtNo == 78:
            print(' 1s 2', '2s 2', '2p 6', '3s 2', '3p 6', '3d 10', '4s 2', '4p 6', '4d 10', '5s 2',
                  '5p 6',
                  '4f 14', '5d 9', '6s 1', sep=' , ')
        elif AtNo == 79:
            print(' 1s 2', '2s 2', '2p 6', '3s 2', '3p 6', '3d 10', '4s 2', '4p 6', '4d 10', '5s 2',
                  '5p 6',
                  '4f 14', '5d 10', '6s 1', sep=' , ')
        else:
            for i in orb:
                if i.__getitem__(1) == 's':
                    if AtNo <= 2:
                        print(i, AtNo)
                        break
                    else:
                        print(i, 2, end=' , ')
                        AtNo = AtNo - 2
                        if AtNo <= 0:
                            break

                elif i.__getitem__(1) == 'p':
                    if AtNo <= 6:
                        print(i, AtNo)
                        break
                    else:
                        print(i, 6, end=' , ')
                        AtNo = AtNo - 6
                        if AtNo <= 0:
                            break
                elif i.__getitem__(1) == 'd':
                    if AtNo <= 10:
                        print(i, AtNo)
                        break
                    else:
                        print(i, 10, end=' , ')
                        AtNo = AtNo - 10
                        if AtNo <= 0:
                            break
                elif i.__getitem__(1) == 'f':
                    if AtNo <= 14:
                        print(i, AtNo)
                        break
                    else:
                        print(i, 14, end=' , ')
                        AtNo = AtNo - 14
                        if AtNo <= 0:
                            break


    # define function for 2d electronic config


    def elecon():
        global AtNo
        if AtNo <= 2:
            if AtNo == 2:
                print("Noble gas Electronic Configurations: ", AtNo)
            else:
                print("Electronic Configurations: ", AtNo)
        elif 2 < AtNo <= 10:
            if AtNo == 10:
                print("Noble gas Electronic Configurations:  2 ,", (AtNo - 2))
            else:
                print("Electronic Configurations: 2 ,", (AtNo - 2))
        elif 10 < AtNo <= 18:
            if AtNo == 18:
                print("Noble gas Electronic Configurations:  2 , 8 ,", (AtNo - 2 - 8))
            else:
                print("Electronic Configurations: 2 , 8 ,", (AtNo - 2 - 8))
        elif 18 < AtNo <= 36:
            if AtNo == 36:
                print("Noble gas Electronic Configurations:  2 , 8 , 18 ,", (AtNo - 2 - 8 - 18))
            elif 21 <= AtNo <= 30:
                print("Electronic Configurations : Unavailable")
            elif AtNo == 19 or 20:
                print("Electronic Configurations: 2 , 8 , 8 ,", (AtNo - 18))
            else:
                print("Electronic Configurations : 2 , 8 , 18 ,", (AtNo - 2 - 18 - 8))
        elif 36 < AtNo <= 54:
            if AtNo == 54:
                print("Noble gas Electronic Configurations:  2 , 8 , 18 , 18 ,", (AtNo - 2 - 8 - 18 - 18))
            elif 39 <= AtNo <= 48:
                print("Electronic Configurations : Unavailable")
            elif AtNo == 37 or 38:
                print("Electronic Configurations: 2 , 8 , 18 , 18 ,", (AtNo - 36))
            else:
                print("Electronic Configurations: 2 , 8 , 18 , 18 ,", (AtNo - 2 - 8 - 18 - 18))
        elif 54 < AtNo <= 86:
            if AtNo == 86:
                print("Noble gas Electronic Configurations:  2 , 8 , 18 , 32 , 18 ,", (AtNo - 2 - 8 - 18 - 32 - 18))
            elif 57 <= AtNo <= 80:
                print("Electronic Configurations : Unavailable")
            elif AtNo == 55 or 56:
                print("Electronic Configurations: 2 , 8 , 18 ,  32 , 18 ,", (AtNo - 54))

            else:
                print("Electronic Configurations: 2 , 8 , 18 ,  32 , 18 ,", (AtNo - 2 - 8 - 18 - 32 - 18))

        elif AtNo > 87:
            print("Electronic Configurations : Unavailable")


    # define function for symbols of element


    def symbol():
        global AtNo
        symb = ['H', "He", 'Li', "Be", "B", "C", "N", "O", "F", 'Ne', 'Na', 'Mg', 'Al', 'Si', 'P', 'S', 'Cl', 'Ar', 'K',
                'Ca', 'Sc', 'Ti', 'V',
                'Cr', 'Mn', 'Fe', 'Co', 'Ni', 'Cu', 'Zn', 'Ga', 'Ge', 'As', 'Se', 'Br', 'Kr', 'Rb', 'Sr', 'Y', 'Zr',
                'Nb', 'Mo', 'Tc', 'Ru',
                'Rh', 'Pd', 'Ag', 'Cd', 'In', 'Sn', 'Sb', 'Te', 'I', 'Xe', 'Cs', 'Ba', 'La', 'Ce', 'Pr', 'Nd', 'Pm',
                'Sm', 'Eu', 'Gd', 'Tb',
                'Dy', 'Ho', 'Er', 'Tm', 'Yb', 'Lu', 'Hf', 'Ta', 'W', 'Re', 'Os', 'Ir', 'Pt', 'Au', 'Hg', 'Tl', 'Pb',
                'Bi', 'Po', 'At', 'Rn',
                'Fr', 'Ra', 'Ac', 'Th', 'Pa', 'U', 'Np', 'Pu', 'Am', 'Cm', 'Bk', 'Cf', 'Es', 'Fm', 'Md', 'No', 'Lr',
                'Rf', 'Ha', 'Unh', 'Ns',
                'Hs', 'Mt', 'Uun', 'Uuu', 'Uub', 'Uut', 'Uuq', 'Uup', 'UUh', 'Uus', "Uuo"]
        print('\n Atomic Symbol :', symb.__getitem__(AtNo - 1), "\n\n Electronic Configurations : --")


    # define function for run all code


    def give_the_final_result():
        get_input = int(input("\n\t1. Get Electronic Configuration by Atomic No.\
        \n\n\t2. Get Electronic Configuration by Atomic Symbol.\n\n(1/2)>>>  "))
        if get_input == 1:
            get_input_at_no()
            if 0 >= AtNo > 118:
                print("Invalid Atomic No")

            else:

                elecon()
                symbol()
                ele_con()
                print('\nAtomic No =', atno)
                sleep(5)
        elif get_input == 2:
            get_input_at_sym()
            elecon()
            symbol()
            ele_con()
            print('\nAtomic No =', atno)
            sleep(5)
        else:
            sleep(5)
            print("\n Enter 1 or 2 not else..")

            give_the_final_result()


    def try_again_or_not(name):
        inn = input(f'\n Try {name} \n (y/n)>>>  ')
        if inn.lower() == 'y':
            give_the_final_result()
        elif inn.lower() == 'n':
            sleep(1)
        else:
            try_again_or_not('another')


    give_the_final_result()
    try_again_or_not('another')
except:
    print("Invalid Input")
    try_again_or_not('again')
    sleep(5)

 

 

Example Output

Electronic Configuration Project using Python

It’s like a chemistry helper built with code! Let’s see how it works.

 

How It Works: Step-by-Step

Let’s break this into easy steps so you can understand and use it!

Step 1: Importing Sleep

The program starts by importing sleep from the time module. This makes the program wait for a few seconds (5 seconds) between steps so you can read the output slowly.

Step 2: Adding a Try-Except Block

The whole program is inside a try and except block. This catches any mistakes (like typing the wrong input) and shows a friendly error message instead of crashing.

 

Step 3: Printing a Fun Heading

It prints a heading: ” — :Chemistry with Python = 🙂 :–” to welcome you!

 

Step 4: Setting Up Global Variables

It uses two variables, AtNo and atno, to store the atomic number. These are “global” so all functions can use them.

 

Step 5: Getting Input from User

There are two ways to enter data:

  • By Atomic Number: The get_input_at_no() function asks you to type an atomic number (e.g., 1 for Hydrogen). It turns your input into a number and waits 5 seconds.
  • By Symbol: The get_input_at_sym() function asks for a symbol (e.g., “H”). It fixes the case (e.g., “h” becomes “H”) and finds the atomic number from a list of symbols.

Step 6: Showing Electronic Configurations

  • 2D Config: The elecon() function gives a simple version of the electronic configuration (e.g., “2, 8” for some elements). It checks ranges like 2 to 10 or 10 to 18.
  • 3D Config: The elecon() function gives a detailed version (e.g., “1s 2, 2s 2, 2p 6” for some elements). It lists orbitals like “1s,” “2p,” etc., with electron counts.

Step 7: Showing the Symbol

The symbol() function uses the atomic number to find and print the element’s symbol from a list.

Step 8: Running the Program

The give_the_final_result() function:

  • Asks if you want to use an atomic number (1) or symbol (2).
  • Runs the right functions based on your choice.
  • Shows the configuration, symbol, and atomic number, then waits 5 seconds.

Step 9: Trying Again

The try_again_or_not() function asks if you want to try another element (type “y” for yes or “n” for no). If you type something else, it asks again.

 

 

Why Is This Great for Class 11 CS?

  • Easy to Learn: It uses functions, loops, and error handling—key topics in Class 11!
  • Fun Topic: Mixing chemistry with coding makes it exciting.
  • Hands-On: You can test it with different elements.

 

 

By Jitendra Singh

A complete solution for the students of class 9 to 12 having subject Information Technology (402), Computer Science (083). Explore our website for all the useful content as Topic wise notes, Solved QNA, MCQs, Projects and Quiz related to the latest syllabus.

Copywrite © 2020-2025, CBSE Python,
All Rights Reserved