Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Periodic Table by bunnychai
# migrated from python 2.7
Element = ['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','Db','Sg','Bh','Hs','Mt','Ds','Rg','Cn','Uut','Fl','Uup','Lv','Uus','Uuo']
Orbital = ['1s', '2s', '2p', '3s', '3p', '4s', '3d', '4p', '5s', '4d', '5p', '6s', '4f', '5d', '6p', '7s', '5f', '6d', '7p']
Room = {'s': 2, 'p': 6, 'd': 10, 'f': 14}
Electron = ['\u2070', '\u00B9', '\u00B2', '\u00B3', '\u2074', '\u2075', '\u2076', '\u2077', '\u2078', '\u2079']
Noble = [2, 10, 18, 36, 54, 86, 118]
Special = {24: '2 2 222 2 222 1 11111', 29: '2 2 222 2 222 1 22222'}
def orbital_model(z):
if z in list(Special.keys()):
return Special[z].split(' ')
else:
model = []
for o in Orbital:
room = Room[o[1]]
if z > room:
z -= room
model.append('2' * (room/2))
else:
magnet = [0] * int((room/2))
for i in range(z):
magnet[int(i%(room/2))] += 1
model.append(''.join([str(x) for x in magnet]))
break
return model
def electronic_conf(z):
conf = []
model = orbital_model(z)
for i, m in enumerate(model):
s = Orbital[i]
e = sum([int(x) for x in m])
up_script = ''.join([Electron[int(x)] for x in str(e)])
conf.append(s + up_script)
return conf
def cloest_noble(z):
a = [x for x in Noble if x < z]
if a:
return a[-1]
def noble_notation(z):
conf = electronic_conf(z)
noble = cloest_noble(z)
if noble:
nc = electronic_conf(noble)
conf = conf[len(nc):]
conf.sort(key=lambda x: int(x[0])*1000 + Room[x[1]])
conf = ['[%s]' % Element[noble-1]] + conf
return ' '.join(conf)
def checkio(element):
z = Element.index(element) + 1
model = ' '.join(orbital_model(z))
notation = noble_notation(z)
return [str(z), notation, model]
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
assert( checkio( 'H' ) == [ "1", "1s¹", "1" ] ), "First Test - 1s¹"
assert( checkio( 'He' ) == [ "2", "1s²", "2" ] ), "Second Test - 1s²"
assert( checkio( 'Al' ) == [ "13", "[Ne] 3s² 3p¹", "2 2 222 2 100" ] ), "Third Test - 1s² 2s² 2p⁶ 3s² 3p¹"
assert( checkio( 'O' ) == ["8", "[He] 2s² 2p⁴", "2 2 211"] ), "Fourth Test - 1s² 2s² 2p⁴"
assert( checkio( 'Li' ) == [ "3", "[He] 2s¹", "2 1" ] ), "Fifth Test - 1s² 2s¹"
Sept. 4, 2013
Comments: