def __init__(self): self.formulas = smf.get_formulas() self.formula = random.choice(self.formulas) self.elements = se.get_elements() self.e1 = self.formula[0] self.s1 = self.formula[1] self.e2 = self.formula[2] self.s2 = self.formula[3] self.aw1 = self.elements[self.e1][2] self.aw2 = self.elements[self.e2][2] self.w1 = self.s1 * self.aw1 self.w2 = self.s2 * self.aw2 self.wt = self.w1 + self.w2 self.p1 = self.w1 / self.wt * 100 self.p2 = self.w2 / self.wt * 100 self.pt = self.p1 + self.p2 self.n1 = self.p1 / self.aw1 self.n2 = self.p2 / self.aw2 self.a1 = self.n1 / min(self.n1, self.n2) self.a2 = self.n2 / min(self.n1, self.n2) self.f = self.s1 / self.a1 self.c1 = round(self.a1 * self.f) self.c2 = round(self.a2 * self.f) self.question = [ '''<div id="question"> Given the percent composition of <br> {0:.2f} % {1} <br> {2:.2f} % {3} <br> and a total weight of {4:.3f} amu, <br> find the molecular formula. Explain your solution completely. </div>'''.format(self.p1, self.e1, self.p2, self.e2, self.wt) ] self.answer = [ ur'''<div id="answer"> $$ atoms \: %s = %.2f \:amu\: %s \cdot \frac{1 \:atom\: %s} {%.3f \: amu} = %.3f \: atoms \: %s $$ $$ atoms \: %s = %.2f \:amu\: %s \cdot \frac{1 \:atom\: %s} {%.3f \: amu} = %.3f \: atoms \: %s $$ $$ smallest = %.3f $$ $$ factor = %d $$ $$ formula = %s_{%d}%s_{%d} $$ $$ formula \: weight = %.3f \: amu $$ </div>''' % (self.e1, self.p1, self.e1, self.e1, self.aw1, self.n1, self.e1, self.e2, self.p2, self.e2, self.e2, self.aw2, self.n2, self.e2, min(self.n1, self.n2), self.f, self.e1, self.c1, self.e2, self.c2, self.wt) ]
def __init__(self): self.elements = se.get_elements() self.m = random.randint(100, 800) / 100. self.s = random.choice(self.elements.keys()) self.name = self.elements[self.s][0] self.mm = self.elements[self.s][2] self.mol = self.m / self.mm self.a = self.mol * 6.02e23 self.question = [ '''<div id="question"> Convert %.2e atoms of %s to grams of %s and moles of %s. Use the unit conversion method and show cancellation of units. </div>''' % (self.a, self.name, self.name, self.name) ] self.answer = [ ur'''<div id="answer"> $$ \require{cancel} %.2e \cancel{atoms \: %s} \cdot \frac{ %.2f {g \: %s} }{ 6.02e23 \: \cancel{atoms \: %s} } = %.2f \: g \: %s $$ $$ \require{cancel} %.2e \cancel{atoms \: %s} \cdot \frac{ 1 \: mol \: %s }{ 6.02e23 \cancel{atoms \: %s} } = %.2e \: mol \: %s $$ </div>''' % (self.a, self.s, self.mm, self.s, self.s, sf(self.m), self.s, self.a, self.s, self.s, self.s, sf(self.mol), self.s) ]
def __init__(self): self.formulas = smf.get_formulas() self.formula = random.choice(self.formulas) self.elements = se.get_elements() self.e1 = self.formula[0] self.s1 = self.formula[1] self.e2 = self.formula[2] self.s2 = self.formula[3] self.aw1 = self.elements[self.e1][2] self.aw2 = self.elements[self.e2][2] self.w1 = self.s1 * self.aw1 self.w2 = self.s2 * self.aw2 self.wt = self.w1 + self.w2 self.p1 = self.w1 / self.wt * 100 self.p2 = self.w2 / self.wt * 100 self.pt = self.p1 + self.p2 self.question = [ '''<div id="question"> Find the percent composition of {0}'''.format(self.e1) ] if self.s1 > 1: self.question[0] += '<sub>{0}</sub>'.format(self.s1) self.question[0] += '{0}'.format(self.e2) if self.s2 > 1: self.question[0] += '<sub>{0}</sub>'.format(self.s2) self.question[0] += '''<br>Explain your solution completely. </div>''' self.answer = [ ur'''<div id="answer"> $$ wt_{%s} = %d \:atom\: %s \cdot \frac{%.3f \: amu} {1 \:atom\: %s} = %.3f \: amu \: %s $$ $$ wt_{%s} = %d \:atom\: %s \cdot \frac{%.3f \: amu} {1 \:atom\: %s} = %.3f \: amu \: %s $$ $$ wt_{tot} = %.3f \: amu $$ $$ \%% \: %s = \frac{wt_{%s}} {wt_{tot}} \cdot 100 = \frac{%.3f \: amu} {%.3f \: amu} \cdot 100 = %.2f \: \%% \: %s $$ $$ \%% \: %s = \frac{wt_{%s}} {wt_{tot}} \cdot 100 = \frac{%.3f \: amu} {%.3f \: amu} \cdot 100 = %.2f \: \%% \: %s $$ $$ \%%_{tot} = %.2f \: \%% $$ </div>''' % (self.e1, self.s1, self.e1, self.aw1, self.e1, self.w1, self.e1, self.e2, self.s2, self.e2, self.aw2, self.e2, self.w2, self.e2, self.wt, self.e1, self.e1, self.w1, self.wt, self.p1, self.e1, self.e2, self.e2, self.w2, self.wt, self.p2, self.e2, self.pt) ]
class elements_with_rev_at_wt(): '''Find pairs of elements on periodic table with reversed atomic weights.''' area = ["periodic table"] skill = ["atomic weight"] pairs=[] elements = se.get_elements() for e1 in elements: for e2 in elements: if elements[e1][1] < elements[e2][1] and elements[e1][2] > elements[e2][2]: pairs.append([e1,e2]) question = '''<div id="question"> Find all pairs of elements where the average atomic weight of the element with the smaller atomic number is more than the average atomic weight of the element with the larger atomic number. </div>''' answer = '<div id="answer"> ' for i in pairs: answer += str(i) answer += '</div> '