Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
OCR GCSE Computing
Python programming
12: A few other things
OCR Computing GCSE
© Hodder Education 2013
Slide 1
Python 12: A few other things
You now have the basic understanding of how to handle
programming in Python.
You can take it as far as you like.
Remember that Python has lots of add-on modules that
make all sorts of programming easier. Take a look at
http://wiki.python.org/moin/UsefulModules
OCR Computing GCSE
© Hodder Education 2013
Slide 2
Python 12: A few other things
import turtle
def shape(line_length):
turtle.forward(line_length)
turtle.right(90)
turtle.forward(line_length)
turtle.right(90)
turtle.title("An example of using a formal argument")
turtle.pencolor("green")
turtle.pensize(4)
for i in range(21):
shape(30+10*i)
turtle.hideturtle()
turtle.mainloop()
OCR Computing GCSE
© Hodder Education 2013
Slide 3
Python 12: A few other things
In the OCR GCSE Computing book that goes with this Dynamic Learning
resource, there is a program that generates a Fibonacci sequence.
Here is a program that uses output from that to draw a shape. You will
notice that it resembles a biological shape – the shell of a Nautilus
mollusc. Fibonacci sequences can generate many natural shapes.
#fibonacci drawing
import turtle
a, b, n = 0, 1, 300
while a < n:
print (a),
turtle.forward (a)
turtle.right (45)
a, b = b, a+b
OCR Computing GCSE
© Hodder Education 2013
Slide 4
Python 12: A few other things
There is a graphics module called tkinter that lets you use a
full graphical interface for your input and output. Try
developing some graphics programs.
You will need to start graphics programs with:
import tkinter
window=tkinter.Tk()
Look up some examples online to get started.
OCR Computing GCSE
© Hodder Education 2013
Slide 5