Python | Science

/ 26 Aug 2013 /
I can honestly say, this is the funnest piece of code, i've ever written, don't ask why, it just is.



n = {}
for line in open('periodic_table.txt'):
    number, element = line.split()
    n[number] = element
    
    
n2 = {}
for line in open('periodic_table.txt'):
    element, number = line.split()[::-1]
    n2[element] = number
    
    
n.update(n2)

q = input('Enter element number or element name: ')

while q:
    try:
        if q.isdigit():
            print('Element number {} is {}'.format(q,n[q]))
        else:
            print('Element number for {} is {}'.format(q,n[q]))
    except:
        print("That's not an element!")
    
    q = input('Enter element number or element name: ')
 
Copyright © 2010 M(ath)+me, All rights reserved