Purpose To practice creating and using tuples Degree of Diff
Solution
CODE:
# Create two lists - lt and gl.
 lt = list()
 gl = list()
# using the extend functionality include all the elements into the list.
 lt.extend([\'H\',\'Hydrogen\',1,1.008])
 lt.extend([\'He\',\'Helium\',2,4.003])
 lt.extend([\'Li\',\'Lithium\',3,6.940])
 lt.extend([\'Be\',\'Beryllium\',4,9.012])
 lt.extend([\'B\',\'Boron\',5,10.810])
 lt.extend([\'C\',\'Carbon\',6,12.011])
 lt.extend([\'N\',\'Nitrogen\',7,14.007])
 lt.extend([\'O\',\'Oxygen\',8,15.999])
 lt.extend([\'F\',\'Fluorine\',9,18.998])
 lt.extend([\'Ne\',\'Neon\',10,20.180])
# Create an iterator to the list.
 it = iter(lt)
# zip the iterator with itself to create List of tuples
 gl = zip(it,it,it,it)
print \"Periodic Table Information\"
 print \'Which element you would like to know about?\'
# Take the input from the user.
 # For python 2.7, use raw_input instead of input.
 num = int(input(\'Enter the atomic number now:\'))
# Iterate through the list of tuples and display the result.
 for item in gl:
    if num == item[2]:
        print \'Symbol: \', item[0]
        print \'Name: \', item[1]
        print \'Number: \', item[2]
        print \'Weight: \', item[3]
        break
   
   
 OUTPUT:
 > python test.py
 Periodic Table Information
 Which element you would like to know about?
 Enter the atomic number now:6
 Symbol: C
 Name: Carbon
 Number: 6
 Weight: 12.011


