December 2015
Intermediate to advanced
416 pages
7h 15m
English
CHAPTER 10
![]()
Functions
Functions are used for two reasons. First, they make code easier to read and understand. Second, they allow code to be used more than once.
Imagine a set of code that draws a tree as shown below. To do this, the programmer executes the following commands:
pygame.draw.rect(screen, BROWN, [60, 400, 30, 45])pygame.draw.polygon(screen, GREEN, [[150, 400], [75, 250], [0, 400]])pygame.draw.polygon(screen, GREEN, [[140, 350], [75, 230], [10, 350]])

Simple Tree
Those three lines of code don’t really pop out as obviously drawing ...
Read now
Unlock full access