130 likes | 253 Views
To Start. Create C:100 folder. Right Click. To Start. Create a short cut to Python 2.7 Another version Python 3.2, but use 2.7. Python27. Figure 1.3. Much of programming is about naming. We name our data Data: The “ numbers ” we manipulate We call our names for data variables
E N D
To Start • Create C:\100 folder Right Click
To Start • Create a short cut to Python 2.7 • Another version Python 3.2, but use 2.7 Python27
Much of programming is about naming • We name our data • Data: The “numbers” we manipulate • We call our names for data variables • We implement algorithms (recipes), and call them functions • Quality of names determined much as in Philosophy or Math • Enough words to describe what you need to describe • Understandable
Variables • Name a value and re-use it • >>> x = 2*8 • >>> x/2 • >>> x • Whenever a variable name appears, it is substituted by its value • A variable name can be reused, redefined
Naming Convention for both Variables and Functions • MUST start with a letter followed by alphanumeric • aVar, cs100, … • CASE matters • ‘Print’ is not the same as ‘print’ • ‘makePicture’ is not the same as ‘makepicture’, nor as ‘Makepicture’ • Multi-word name • First letter is capitalized • Convention, not absolute rule • Use sensible, meaningful name
Figure 1.5 • Name Space == Class
Python Overview • Data Objects: int, float • Operators • Expressions • Naming • Assignment Statements (variables, names) • Python Interpreter (read, evaluate, print)
turtle module • Simple graphics programming • Abstraction • Fun and easy
Import turtle module • >>> import turtle • Turtle attributes • Position, heading (direction), color, tail position • >>> myT = turtle.Turtle() • With myT • myT.forward(100), myT.backward(100) • myT.right(90), myT.left(45) • myT.goto(-200,90), myT.circle(50), myT.color(“red”) • myT.up(), myT.down() • myT.write(“Hello!”) • http://www.eg.bucknell.edu/~hyde/Python3/TurtleDirections.html