xin liu. * use python 3.0 or later version * major differences from earlier versions * interactive...
TRANSCRIPT
Xin Liu
*CPSC 231 TutorialJan 16, 2013
*Getting started with python
*Use python 3.0 or later version
*Major differences from earlier versions
* Interactive mode
* For quick experiments
* “python3” to enter
* print(’python programming is fun!’)
* “Ctl+D” to quit
*Script mode
* For regular programs, that can be executed repeatedly
* Edit a program (with gedit)
* python3 myprogram.py
*The first python program
*In gedit, create the first.py containing the following program
*In terminal, run the program by typing
print(‘hello world!’)print(‘this is my first python program’)Print(‘it’s funny’)
Python3 first.py
*Turtle graphics
*http://docs.python.org/3/library/turtle.html
(0, 0)
(100, 100)
Cartesian plane
*Turtle commands
* import turtle
* clear()
* title(‘window name’)
* goto(x, y)
* forward(distance)
* back(distance)
* left(angle)
* right(angle)
* circle(radius)
* begin_fill()
* end_fill()
* pencolor(r, g, b), 0 <= r, g, b <= 1
* fillcolor(r, g, b)
* write(‘a string’)
*A drawing program
*Just to get a feeling of programming
from turtle import *color('red', 'yellow')begin_fill()while True: forward(200) left(170) if abs(pos()) < 1: breakend_fill()done()