Presentation is loading. Please wait.

Presentation is loading. Please wait.

You SHOUD HAVE.. C:\100 folder A desktop shortcut to “IDLE (Python34)”

Similar presentations


Presentation on theme: "You SHOUD HAVE.. C:\100 folder A desktop shortcut to “IDLE (Python34)”"— Presentation transcript:

1 You SHOUD HAVE.. C:\100 folder A desktop shortcut to “IDLE (Python34)”

2 Python file A file to save a program, and re-use it From IDLE, select ‘File>New FIle’ Enter Python instructions Save with.py extension

3 Python Modules & Packages A collection of useful tools/resources Math numPy, sciPy bioPython pyGame

4 turtle module Simple graphics programming How to use it ? Import ‘turtle’ module Create a turtle, and NAME it to your own name Say, you named a turtle ‘xxx.’ Can have more than one turtles at a time – tell them apart by names Call actions to take (METHOD) xxx.goto()

5 Turtle in Python >>> import turtle Turtle attributes Position, heading (direction), color, tail position >>> myT = turtle.Turtle() Turtle screen 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

6 Figure 1.9

7 turtle module >>> import turtle >>> myT = turtle.Turtle() What is “.” between turtle and Turtle() ? turtle => class (generic object) Turtle() => method (action, function, constructor) Rough interpretation: get ‘turtle’ type and do ‘Turtle()’ >>> myT.color(“red”) Get ‘myT’ turtle and color it red attribute

8 Other Methods >>> 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 Official Python turtle page https://docs.python.org/release/3.1.3/library/turtle.html

9 Which methods to use ? Suppose ‘myT’ turtle is created Draw a circle --- myT.circle(100) Draw a thicker circle – myT.width(5) Find out the location (x,y) of myT – myT.position() Move myT to (100,-50) – myT.goto(100,-50) Stop drawing – myT.up() Find out the screen sizes – myT.window_width() and myT.window_height()

10 Lab 1 Draw any two circles of olympics rings After done, click on ‘Print Screen’ button at upper right, save it to a MS Word file with your name, and email to kim@cs.uml.edukim@cs.uml.edu

11 HW 1 Due on 9/14 (Mon) class time From python.org/downloads, download python3.4.3 and install in on your computer HW #1 – Draw five circles of olympics rings Email your python program of olympics rings to kim@cs.uml.edu


Download ppt "You SHOUD HAVE.. C:\100 folder A desktop shortcut to “IDLE (Python34)”"

Similar presentations


Ads by Google