I am writing a code in python which gives basic information about the elements in periodic table when user inputs the symbol of that element.
We have to make it using class object. We can't use multiple classes here to choose from but modules can be made. We can use dictionary, modules and file handling, but use of conditions and switch case isn't allowed.
I have made a separate dictionary for these elemental properties but I want to know how to make it in the way when the user inputs the symbol, it shows the the element's properties.
Here's the library:
def Hydrogen(H):
i='Hydrogen'
n=1
m=1.007
r=0.12
ir=0.208
eng=2.1
def Helium(He):
i='Helium'
n=2
m=4.00260
r=0.118
ir='NA'
eng='NA'
def Lithium(Li):
i='Lithium'
n=3
m=6.941
r=0.145
ir=0.06
eng=1
def Beryllium(Be):
i='Beryllium'
n=4
m=9.01218
r='NA'
ir='NA'
eng=1.5
def Boron(B):
i='Broron'
n=5
m=10.81
r=0.098
ir=0.027
eng=2.0
def Carbon(C):
i='Carbon'
n=6
m=12.11
r=0.091
ir="0.26(-4); 0.015(+4)"
eng=2.5
def Nitrogen(N):
i='Nitrogen'
n=7
m=14.0067
r=0.092
ir="0.171 (-3); 0.011(+5); 0.016(+3)"
eng=3.0
def Oxygen(O):
i='Oxygen'
n=8
m=15.999
r=0.074
ir=0.14
eng=3.5
def Fluorine(F):
i='Fluorine'
n=9
m=18.998403
r=0.135
ir="0.135 (-1); 0.007 (+7)"
eng=4
def Neon(Ne):
i='Neon'
n=10
m=20.179
r=0.16
ir='NA'
eng='NA'
def Sodium(Na):
i='Sodium'
n=11
m=22.98977
r=0.196
ir=0.95
eng=0.9
def Magnesium(Mg):
i='Magnesium'
n=12
m=24.305
r=0.16
ir=0.065
eng=1.6
def Aluminium(Al):
i='Aluminium'
n=13
m=26.98154
r=0.143
ir=0.05
eng=1.5
def Silicon(Si):
i='Silicon'
n=14
m=28.0855
r=0.132
ir="0.271 (-4); 0.041(+4)"
eng=1.8
def Phosphrus(P):
i='Phosphorus'
n=15
m=30.9738
r=0.104
ir=0.034
eng=2.1
def Sulfur(S):
i='Sulfur'
n=16
m=32.06
r=0.127
ir="0.184(-2); 0.029(+6)"
eng=2.5
def Chlorine(Cl):
i='Chlorine'
n=17
m=35.453
r=0.127
ir="0.184(-2); 0.029(+6)"
eng=3.0
def Argon(Ar):
i='Argon'
n=17
m=39.948
r=0.192
ir="NA"
eng='NA'
def Potassium(K):
i='Potassium'
n=19
m=39.0983
r=0.235
ir=0.133
eng=0.8
def Calcium(Ca):
i='Calcium'
n=20
m=40.08
r=0.197
ir=0.099
eng=1.0
def Scandium(Sc):
i='Scandium'
n=21
m=44.9559
r=0.161
ir=0.083
eng='NA'
def Titanium(Ti):
i='Titanium'
n=22
m=47.88
r=0.147
ir='0.09(+2); 0.068(+4)'
eng=1.5
def Vanadium(V):
i='Vanadium'
n=23
m=50.9414
r=0.134
ir='0.074(+3); 0.059(+5)'
eng=1.6
def Chromium(Cr):
i='Chromium'
n=24
m=51.996
r=0.127
ir='0.061(+3); 0.044(+6)'
eng=1.6
def Manganese(Mn):
i='Manganese'
n=25
m=54.9380
r=0.126
ir='0.08(+2); 0.046(+7)'
eng=1.5
def Iron(Fe):
i='Iron'
n=26
m=55.85
r=0.126
ir='0.076(+2); 0.064(+3)'
eng=1.8
def Cobalt(Co):
i='Cobalt'
n=27
m=58.9332
r=0.125
ir='0.078(+2); 0.063(+3)'
eng=1.8
def Nickel(Ni):
i='Nickel'
n=28
m=58.71
r=0.124
ir='0.069(+2); 0.06(+3)'
eng=1.8
def Copper(Cu):
i='Copper'
n=29
m=63.546
r=0.128
ir='0.096(+1); 0.069(+3)'
eng=1.9
def Zinc(Zn):
i='Zinc'
n=30
m=65.37
r=0.138
ir='0.074(+2)'
eng=1.6
def Gallium(Ga):
i='Vanadium'
n=31
m=69.72
r=0.161
ir=0.083
eng='NA'
def Germanium(Ge):
i='Germanium'
n=32
m=72.64
r=0.134
ir='0.074(+3); 0.059(+5)'
eng=1.6
And the code I will be using to import the dictionary and use to provide the data is:
class Elements:
def __init__(self, i, n, m, r, ir, eng):
self.i = i
self.n = n
self.m = m
self.r = r
self.ir = ir
self.eng = eng
def show(self):
print("\nElemental properties are:\n")
print("\nName: ", self.i)
print("\nAtomic Number: ", self.n)
print("\nAtomic Mass: ", self.m)
print("\nVanderwaals Radius: ", self.r)
print("\nIonic Radius: ", self.ir)
f = input("Enter the formula of element to get it's data: ")
I want to know how to call the function by taking the input from the user and get the information in the previous order without using conditional statements like if
-else
or switch case
.
If I have to change my whole code that will also work but I want my output that way.