#Submitted By: Gourav Garg #E-mail id: gouravga@buffalo.edu #Person No.: 5016-4951 #The program calculates the mass of an element #It calculates the average atomic weight of Hydrogen #Calculates Mean, Standard Deviation of a sample with given masses #Sorts a list #Finds minimum and maximum number from a list #Calculates No. of moles of a substance with given masses and constant molecular weight and plots moles vs mass graph # Asking user for number of protons and neutrons p = int(raw_input('Number of protons=')) n = int(raw_input('Number of neutrons=')) m = p+n print ("Mass of an Atom = %s\n\n" %m) ##################################################################################################### print "Calculating Average Atomic Weight" print "\n There are two isotopes of hydrogen: Protium and Deuterium" # we will calculate the atomic weight of Hydrogen # we have considdered the two most abundant isotopes of Hydrogen i.e. Protium and Deuterium. H1 = 0.9998 #Abundance of Protium isotope H2 = 1-H1 #Abundance Deuterium isotope #calculating the atomic weight of first isoptope P_wt = 2.013*H1 #Atomic weight of Protium x abundance #calculating the atomic weight of second isotope D_wt = 3.016*0.0111 # Atomic weight of Deuterium x abundance print ("Atomic Weight of Protium= %s\n" %P_wt) print ("Atomic Weight of Deuterium= %s\n" %D_wt) #calculating average atomic weight H_wt = P_wt+D_wt print ("Average Atomic Weiht of Hydrogen = %s \n" %H_wt) #this average atomic weight calculation does not consider other isotopes as they are only available in traces ################################################################################################### #Defining an element for example Hyrogen dict = {'Name': 'Hydrogen', 'Atomic Weight': 2, 'Atomic Number': 1, 'Group': 1, 'Symbol': "H", 'State' : 'Gas', 'Appearance':'Colorless' }; print "Description of an element:\n" print "Element Name: ", dict['Name']; print "Symbol: ",dict['Symbol']; print "Atomic weight: ", dict['Atomic Weight']; print "Atomic Number: ", dict['Atomic Number']; print "Group Category: ", dict['Group']; print "State: ", dict['State']; print "Appearance: ", dict['Appearance']; #################################################################################################### #Types of Bonding in Atoms bond_list1 = ['Ionic', 'Covalent', 'Metallic', 'Hydrogen Bond'] bond_list2 = ['Ionic', 'Covalent', 'Metallic', 'Secondary'] #bonds list print "\nDifferent Types of chemical Bonds:" , bond_list1[0:4] print "\nDecreasing Bond Strength :" , bond_list2[0:4] print "\nExamples of bonding:\n" Example_bond = ['Nacl', 'O2', 'Zn', 'HF'] for a1,a2 in zip(bond_list2, Example_bond): print a1+ ": " +a2 bond_state = ['Crystalline Solid', 'Solid/Liquid/gas', 'Malleable Solid'] print "\nDefining the State of bonds at standard temperature & Pressure\n" for b1,b2 in zip(bond_list2[0:3],bond_state): print b1+ ": "+b2 #################################################################################################### #calculating the ionic character #consiering the example of MgO and findind the ionic character for the same #importing the ncessary packages to define the function from math import exp xA = 2.20 #electronegativity of Hydrogen xB = 3.5 #electronegativity of O def subtract(a1, b1): return (a1 - b1) #calling the subtract function a1 = 1 b1 = exp(-0.25 *(xA - xB)**2) #exp function is called from the math library print "Ionic charatcer of water(H2O):\n" print eval('subtract(a1, b1)') #this calculation can be used for any compound to find which bonding dominates ##################################################################################################### print "\nFirst 10 elements of periodic table with their valencies\n" Element_list = ( 'H', 'He', 'Li', 'Be', 'B', 'C', 'N', 'O', 'F', 'Ne') Valency_list = ( 1, 2, 1, 2, 3, 4, 5, 6, 7, 8 ) for c1,c2 in zip(Element_list, Valency_list): print c1+ ": "+ str(c2) a = float(input('Enter valency of element?\n')) print str(a) if a<0: print "Enter a positive number\n" else: if a < 4: print "The Ion is Cation\n" print "The Element can be categorized as a Metal\n" else: print "The Ion is Anion\n" print "The Element can be categorized as a Non-Metal\n" ############################################################################################################ # Elements with minimum and maximum mass mass_list = [120, 400, 200, 40, 550, 1000, 340, 99, 80] #A user defined list of masses of few elements def min_Mass(List): # function to find minima in the list min_value = List[0] # iterating through the elements of the list using For loop to find the minimum element for i in List[1:]: if i < min_value: min_value = i return min_value def max_Mass(List): #Function to find maxima in the list max_value = List[0] for j in List[1:]: if j > max_value: max_value = j return max_value print "The minimum mass in the list is:", min_Mass(mass_list) print "The maximum mass in the list is:", max_Mass(mass_list) ################################################################################################# ##checking the distribution of a sample of mass of elements import numpy as np import scipy.stats as st import matplotlib.pyplot as pt # sample of elements mass.. sample_mass_list = [1, 4, 8, 30, 45, 10, 3, 70, 82, 20, 4, 40, 45, 200, 150, 110, 120, 300, 12, 15, 30, 38, 168, 45, 55, 76] ## sorting the elements in the sample # sorting will arrange the list in an order of incresing numbers sample_mass_list.sort() ## calculating the mean of the distribution sample_mean = np.mean(sample_mass_list) ## calculating the standard deviation of the distribution sample_deviation = np.std(sample_mass_list) ## fitting the density curve using the mean and standard deviation calculated density_curve = st.norm.pdf(sample_mass_list, sample_mean, sample_deviation) pt.plot(sample_mass_list, density_curve, '-*') # "-*" will show the density concentration ## plotting the histogram with the density curve fitted. pt.hist(sample_mass_list, normed = True) print "\nHistogram displaying the Mass of Elements" pt.xlabel("Mass of the Elements") pt.ylabel("Density") pt.title("Distribution of the Mass of elements") pt.show() ##################################################################################################### #Calculating number of moles with given mass and constant molecular weight import matplotlib.pyplot as pt cmass = [10, 22, 5, 7, 9, 210,30, 40, 50, 60, 70, 85, 25, 34, 100, 112, 140, 150] # molecular mass of water .. molecular_Mass = 18 #sorting the mass of elements #cmass.sort() #no. of moles n_moles = [ i / molecular_Mass for i in cmass ] n_moles.sort() #sorting the no. of moles list print n_moles # plotting the relation between cmass and n_moles pt.scatter(cmass, n_moles) print "\nPlot displaying Moles - Mass Relationship" pt.xlabel("Mass of the compound") pt.ylabel("No. of Moles") pt.title("Moles v/s Mass") pt.show()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question