# Better Functions

Grey overlay

Pink

Green

Blue

Cream

Liliac

Purple

Yellow

## 1 Objectives

### Developing the Programming and Development and Algorithm learning strands, specifically:

• further developing understanding of repetitions (loops) in programming and being able to use for loops in creating patterns.
• further developing understanding of functions in programming and being able to create simple functions that serve a single purpose.
• developing understanding of the need for data structure list and being able to apply list data structure.

## 2 Lists

### Learn It

• A standard variable is handy for storing a single piece of information.
```yourName='Jane'
yourAge=50
likeCrisps=True
```
• Sometimes, it's handy to store several pieces of information so that we can access them all when we need them. For this, we use a list.
• Type these commands in the INTERPRETER one at a time to get the hang of manipulating lists:
```someColours=['Red','Blue','Pink','Black']

print(someColours[0])
someColours.append('Green')

print(someColours)

someColours.sort()
print(someColours)

someColours.reverse()
print(someColours)

someColours.pop()
print(someColours)

someColours.pop(1)
print(someColours)
```
• You can type the commands into this Trinket, if you find it easierâ€¦

### Code It

• Using lists, we can get more flexibility over the patterns we can create.
```import turtle

wn = turtle.Screen()
wn.bgcolor("white")
wn.title("List Practice")

tess = turtle.Turtle()
tess.pensize(5)

def colouredSquare(sideLength,newColour):
tess.color(newColour)
for x in range(4):
tess.forward(sideLength)
tess.left(90)

colourList=['red','green','blue','orange','hotpink','purple']

for eachColour in colourList:
colouredSquare(75,eachColour)  # Draw a square in the current colour.

# The len() function will tell you how long a list is, or how many characters are in a string.
# I'm using it here to calculate the angle I need, based on the size of the list.
tess.left(360/len(colourList))

wn.mainloop()
```
• As always, this Trinket may be handy to use to experiment withâ€¦

## 3 Assessment

```Name a Python colour (XYZ when done): red