Latest revision |
Your text |
Line 1: |
Line 1: |
| == Part 1: Review == | | == Resources == |
| * math: using python as a calculator
| | |
| **addition, subtraction, multiplication, division
| | * [[Python data types cheat sheet]] |
| **division shows something different: <code>8/2</code> versus <code>2*2</code>
| | * [[Python loops cheat sheet]] |
| * <tt>type()</tt>
| | * [http://mako.cc/teaching/2015/cdsw-spring/state_capitals.py state_capitals.py] -- the state capitals example. |
| ** there are different types of things in python (called objects) | | * [http://communitydata.cc/~mako/cdsw-au2015-lecture1-20151010.ogv cdsw-au2015-lecture1-20151010.ogv] -- Professor Mako Hill's lecture video, which covers most of the concepts from today's lecture. |
| ** variables that "know about the decimal place" (int) and variables that don't (floats) | | |
| * variables
| | == Lecture outline == |
| ** assignment of variaibles
| | |
| ** e.g., math with variables: scale up a recipe, into an assignment | |
| ** you can assign to a variable and it will replace the old value
| |
| * strings
| |
| ** things within quotation marks
| |
| ** adding strings with "concatination" (smushing things together)
| |
| ** e.g., <code>print("Hello" + name)</code>
| |
| ** concatenating strings and integers don't work (e.g., <code>print(1 + "mako")</code>)
| |
| ** 1 is different than "1"; name is different than "name"
| |
| ** single quotes versus double quotes (python doesn't care)
| |
| ** you can also multiply strings! (although it's not clear why you want to weird)
| |
| * booleans
| |
| ** comparisons (e.g., <code>1 == 1</code> or <code>1 == 0</code>)
| |
| *** you can compare strings (case sensative!)
| |
| *** also >, <, and !=
| |
| ** type() shows that the output of True or False is <code>bool</code>
| |
| ** e.g., <code>"i" in "team"</code>
| |
| ** e.g., <code>"i" not in "team"</code>
| |
| * <tt>if</tt>/<tt>elif</tt>/<tt>else</tt> ('''move to external file''') | |
| ** if, something that evaluates to a boolean, and then colon
| |
| ** e.g., <code>if "mako" in "makoshark"</code>
| |
| ** e.g., adding else example: <code>if brother_age > sister_age</code>
| |
| ** e.g., temperature range (e.g., if temp<65 is cold; temp>80 is hot; otherwise, just right)
| |
| ** e.g., adding elif: fix the bug in the previous program if they were the same age
| |
| ** indent with spaces (we use 4 spaces!)
| |
| * functions
| |
| ** has a parentheses
| |
| ** we've already learnd examples of this: exit(), help(), type()
| |
|
| |
|
| == Part 2: New programming concepts ==
| |
| === Lists === | | === Lists === |
|
| |
|
Line 73: |
Line 45: |
|
| |
|
| === loops and more flow control === | | === loops and more flow control === |
| ''See also: [[DS4UX_(Spring_2016)/Working_within_loops|working within loops]].''
| |
|
| |
|
| * <tt>for</tt> loops | | * <tt>for</tt> loops |
Line 95: |
Line 66: |
| * <tt>break</tt> | | * <tt>break</tt> |
| * <tt>input()</tt> | | * <tt>input()</tt> |
| | |
| | === dictionaries === |
| | * purpose |
| | * initialization |
| | * accessing elements |
| | * adding elements |
| | * changing elements |
| | * <tt>keys()</tt> and <tt>values()</tt> |
|
| |
|
| === modules === | | === modules === |
| * purpose | | * purpose |
| * builtins | | * builtins |
| | * imports |
| * <tt>import random</tt> | | * <tt>import random</tt> |
| * <tt>random.randint</tt> | | * <tt>random.randint</tt> |
| * <tt>random.choice</tt> | | * <tt>random.choice</tt> |
| * <tt>random.sample</tt>
| |
|
| |
|
| === walk through favorite_buildings.py === | | === walk through state_capitals.py === |
| Where <code>favorite_buildings.py</code> from http://jtmorgan.net/ds4ux/week2/others/favorite_buildings.py is the grand finale and synthesis of lecture material.
| |
|
| |
|
| | Where state_capitals.py from http://mako.cc/teaching/2015/cdsw-spring/state_capitals.py is the grand finale and synthesis of lecture material. |
|
| |
|
| [[Category:DS4UX (Spring 2016)]] | | [[Category:DS4UX (Spring 2016)]] |