130 likes | 261 Views
This guide covers fundamental concepts in Python programming, focusing on variable naming conventions and the use of the turtle module for simple graphics. It highlights the importance of meaningful names for variables and functions, and how these names are essential for clarity in code. Additionally, you'll learn to manipulate turtle graphics, including controlling movement, changing colors, and writing text, all while solidifying your understanding of how Python interprets and executes your coding commands.
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