<div dir="ltr"><br><div><div># -*- coding: utf-8 -*-</div><div>"""</div><div>Created on Thurs June 22, 2017</div><div><br></div><div>Course: PYT-PR (Saisoft.net)</div><div><br></div><div>Instructor:</div><div>Kirby Urner</div><div><a href="mailto:kirby.urner@gmail.com">kirby.urner@gmail.com</a></div><div><br></div><div>Audio Check (6:15 PM PDT)</div><div><br></div><div>Introduction</div><div>   What's an Object?</div><div><br></div><div>Types we've seen briefly: </div><div>int float string datetime list...</div><div>... lets keep adding to that </div><div>python_types.py</div><div><br></div><div>Mapping versus Sequence:</div><div>   dict & set</div><div>   </div><div>Looping with for</div><div>   more string formatting</div><div><br></div><div>Lab 1:  In file elements.py, create </div><div>named tuples for the first 10 elements </div><div>of Periodic Table.  Need at least: </div><div>protons, abbreviation, long name. </div><div>Print all elements in a for loop.</div><div><br></div><div>New types:  </div><div>range</div><div>enumerate</div><div>collections.namedtuple</div><div>collections.Counter</div><div><br></div><div>Lab 2: create a dict with abbreviations</div><div>as keys, for your elements, in elements.py</div><div><br></div><div>Worth watching (some other time):</div><div><a href="https://youtu.be/lyDLAutA88s">https://youtu.be/lyDLAutA88s</a></div><div>David Beazley | Keynote: Built in Super Heroes</div><div><br></div><div>Objects:</div><div>  What is an API?</div><div>  Internal state</div><div>  Dot Notation (going within)</div><div>  </div><div>Review / new:  sys module and sys.path</div><div>os module.  elements.py is a module too</div><div><br></div><div>Immutable versus Mutable:</div><div>  tuple versus list, what's the difference?</div><div>  </div><div>Callable verus not Callable</div><div>  does it need "a mouth" (with or without arguments?)</div><div><br></div><div>Lab3: create more formatted printing </div><div>for elements.py (elements_lab3.py)</div><div><br></div><div>Summary of Session 02</div><div>"""</div><div><br></div></div><div>From the shared Google drive lesson folder:</div><div><br></div><div><div># -*- coding: utf-8 -*-</div><div>"""</div><div>Created on Thu Jul  7 19:36:12 2016</div><div><br></div><div>@author: kurner</div><div><br></div><div>LAB:</div><div><br></div><div>Create a namedtuple to represent an element.</div><div>Use the Periodic Table to define 10 namedtuples</div><div>corresponding to the first 10 elements. Such</div><div>as Hydrogen, Helium and so on.</div><div><br></div><div>Need at least: </div><div>protons, abbreviation (1 or 2 letters), long name</div><div><br></div><div>Example:</div><div>Employee = namedtuple("Job Holder", "name age title")</div><div><br></div><div>Hint:</div><div>"{:10} | {:10} | {:10}".format(4.5, 5.8, 9.0)</div><div>"""</div><div><br></div><div>from collections import namedtuple</div><div><br></div><div>Element = namedtuple("Atom", "protons abbrev long_name mass")</div><div><br></div><div># FIRST 10 ELEMENTS FROM PERIODIC TABLE</div><div>all_elements = dict()</div><div>all_elements["H"]  = Element(1, "H", "Hydrogen", 1.00794)</div><div>all_elements["He"] = Element(2, "He", "Helium", 4.002602)</div><div>all_elements["Li"] = Element(3, "Li", "Lithium", 6.941)</div><div>all_elements["Be"] = Element(4, "Be", "Beryllium", 9.012182)</div><div>all_elements["B"]  = Element(5, "B", "Boron", 10.811)</div><div>all_elements["C"]  = Element(6, "C", "Carbon", 12.0107)</div><div>all_elements["N"]  = Element(7, "N", "Nitrogen", 14.0067)</div><div>all_elements["O"]  = Element(8, "O", "Oxygen", 15.9994)</div><div>all_elements["F"]  = Element(9, "F", "Fluorine", 18.998403)</div><div>all_elements["Ne"] = Element(10, "Ne", "Neon", 20.1797)</div><div>all_elements["Na"] = Element(11, "Na", "Sodium", 22.98976928)</div><div>all_elements["Mg"] = Element(12, "Mg", "Magnesium", 24.4050)</div><div>all_elements["Al"] = Element(13, "Al", "Aluminum", 26.8815386)</div><div>all_elements["Si"] = Element(14, "Si", "Silicon", 28.0855)</div><div>all_elements["P"]  = Element(15, "P", "Phosphorous", 30.973762)</div><div>all_elements["S"]  = Element(16, "S", "Sulfur", 32.065)</div><div>all_elements["Cl"] = Element(17, "Cl", "Chlorine", 35.453)</div><div>all_elements["Ar"] = Element(18, "Ar", "Argon", 39.948)</div><div>all_elements["K"]  = Element(19, "K", "Potassium", 39.0983)</div><div>all_elements["Ca"] = Element(20, "Ca", "Calcium", 40.078)</div><div>all_elements["Sc"] = Element(21, "Sc", "Scandium", 44.955912)</div><div><br></div><div>ordered_elements = \</div><div>["H", "He", "Li", "Be", </div><div>"B", "C", "N",</div><div>"O", "F", "Ne", "Na", </div><div>"Mg", "Al", "Si", "P", </div><div>"S", "Cl", "Ar", "K", "Ca", "Sc"]</div><div><br></div><div>print("          PERIODIC TABLE")</div><div>print()</div><div>print(" Protons       Abbrev          Mass")</div><div>print("-" * 50)</div><div>for atom in ordered_elements:</div><div>    the_atom = all_elements[atom]</div><div>    print("{0:>10} | {1:^10} | {2:12.8} |".format(the_atom.protons, </div><div>                                  the_atom.abbrev, the_atom.mass))</div><div><br></div><div><br></div></div></div>