pair programming project - axsied€¦  · web viewpair programming projectpair programming...

19
Pair Programming Project

Upload: others

Post on 05-Jan-2020

38 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Pair Programming Project - Axsied€¦  · Web viewPair Programming ProjectPair Programming Project. Pair Programming Project. Pair Programming Project. Table of Contents. program1.py

Pair Programming Project

Page 2: Pair Programming Project - Axsied€¦  · Web viewPair Programming ProjectPair Programming Project. Pair Programming Project. Pair Programming Project. Table of Contents. program1.py

Pair Programming Project | Challenge 3 2

Page 3: Pair Programming Project - Axsied€¦  · Web viewPair Programming ProjectPair Programming Project. Pair Programming Project. Pair Programming Project. Table of Contents. program1.py

Table of Contentsprogram1.py – Hello world....................................................................................................................4

Extending program1.py – “ask someone their name”...........................................................................5

program2.py – Moving a turtle.............................................................................................................6

program2.py – Using procedure definitions.........................................................................................7

Challenge 1 – Making shapes................................................................................................................8

Challenge 2..........................................................................................................................................10

Tree fractal......................................................................................................................................12

Challenge 3..........................................................................................................................................12

Colour and turtle shape...................................................................................................................13

Challenge 4..........................................................................................................................................14

Name commenter........................................................................................................................15

Text adventure game...........................................................................................................................15

Pair Programming Project | Challenge 3 3

Page 4: Pair Programming Project - Axsied€¦  · Web viewPair Programming ProjectPair Programming Project. Pair Programming Project. Pair Programming Project. Table of Contents. program1.py

Session 1

program1.py – Hello world

Task:

The program will put the text “hello world” onto the screen

Instructions:

1. First load IDLE2. Save your program as “program1.py”3. Type the program below4. Run your program by pressing F5

Type in this:

Source code: program1.py

Your program will look like this:

output

Pair Programming Project | Challenge 3 4

Page 5: Pair Programming Project - Axsied€¦  · Web viewPair Programming ProjectPair Programming Project. Pair Programming Project. Pair Programming Project. Table of Contents. program1.py

Extending program1.py – “ask someone their name”

Task:

The program will ask you your name then say hello to you.

Instructions:

1. Adapt program1.py by adding the code below2. The hash symbol # is used for comments. These show what the code does. You don’t have to

type these

Source code: program1.py

Output

Pair Programming Project | Challenge 3 5

Page 6: Pair Programming Project - Axsied€¦  · Web viewPair Programming ProjectPair Programming Project. Pair Programming Project. Pair Programming Project. Table of Contents. program1.py

program2.py – Moving a turtle

Task:

You will make a turtle and move it

Instructions:

1. Create the following program which will make a new turtle and move it on the screen

Source code: program2.py

Output

Pair Programming Project | Challenge 3 6

Page 7: Pair Programming Project - Axsied€¦  · Web viewPair Programming ProjectPair Programming Project. Pair Programming Project. Pair Programming Project. Table of Contents. program1.py

program2.py – Using procedure definitions

Task:

Make a procedure called square and call it

Why:

We use procedures to group instructions together under one name.

Instructions:

1. Adapt your program to use a procedure definition2. Call the program

Source code: program2.py

Pair Programming Project | Challenge 3 7

Page 8: Pair Programming Project - Axsied€¦  · Web viewPair Programming ProjectPair Programming Project. Pair Programming Project. Pair Programming Project. Table of Contents. program1.py

Output

Challenge 1 – Making shapes

1. Make this shape by using the square procedure

2. Make a new procedure definition called triangle and call it

Pair Programming Project | Challenge 3 8

Page 9: Pair Programming Project - Axsied€¦  · Web viewPair Programming ProjectPair Programming Project. Pair Programming Project. Pair Programming Project. Table of Contents. program1.py

3. Make this shape by calling the triangle procedure

4. Make this shape by calling the triangle procedure

5. Make this shape by calling the triangle procedure

6. Now create another definition for a different shape.

Pair Programming Project | Challenge 3 9

Page 10: Pair Programming Project - Axsied€¦  · Web viewPair Programming ProjectPair Programming Project. Pair Programming Project. Pair Programming Project. Table of Contents. program1.py

Session 2Look at this code – we do the same two lines of code four times

We can use a for loop to repeat the same code

Challenge 2

Try to make procedure definitions for the following shapes

Procedure definition Shapepentagon

Pair Programming Project | Challenge 3 10

Page 11: Pair Programming Project - Axsied€¦  · Web viewPair Programming ProjectPair Programming Project. Pair Programming Project. Pair Programming Project. Table of Contents. program1.py

octagon

circle

Spirograph

(it doesn’t need to look exactly the same)

Pair Programming Project | Challenge 3 11

Page 12: Pair Programming Project - Axsied€¦  · Web viewPair Programming ProjectPair Programming Project. Pair Programming Project. Pair Programming Project. Table of Contents. program1.py

Fractals use repetition to repeat the same small part of something again and again. You see these in nature with plants, trees and shells.

Tree fractal

Copy the following code to make a procedure definition for a tree:

Replace alex with the name of your turtle.

You can change 75 to another number. This is the length of each branch of the tree.

Challenge 3

Now try to make a forest like this. (The colours and trees don’t need to match).

Pair Programming Project | Challenge 3 12

Page 13: Pair Programming Project - Axsied€¦  · Web viewPair Programming ProjectPair Programming Project. Pair Programming Project. Pair Programming Project. Table of Contents. program1.py

Session 3

Colour and turtle shape

Try calling the following procedures with your turtle. Play with them until you understand what they do.

Procedure What it doesChanges the background colour of the window

Changes the line colour of the turtleChanges the turtle shape – options are:turtle, arrow, blank, circle, classic, square, triangleLift up the penDraw with the pen

Change the pen size

alex.speed(10) Change the speed of the turtle

Pair Programming Project | Challenge 3 13

Page 14: Pair Programming Project - Axsied€¦  · Web viewPair Programming ProjectPair Programming Project. Pair Programming Project. Pair Programming Project. Table of Contents. program1.py

Challenge 4

Create a scene using the turtle. Use the following for ideas. You can combine any of these together, or you might like to come up with something completely different.

Images from pixabay (royalty free, no attribution required)

Draw the scene that you are trying to create below first

Pair Programming Project | Challenge 3 14

Page 15: Pair Programming Project - Axsied€¦  · Web viewPair Programming ProjectPair Programming Project. Pair Programming Project. Pair Programming Project. Table of Contents. program1.py

Session 4Name commenter

1. Type our the code below and test it with the names “alex”, “batman” and another name2. Adapt the code so that it uses lots of names and says different replies

Code:

Output:

If statements allow you to branch code to different sections based on a condition.

Text adventure game

A text adventure is an adventure game which allows the player to select different choices by typing in what they want to do. Look at the code below to see how it works.

Source code:

Pair Programming Project | Challenge 3 15

Page 16: Pair Programming Project - Axsied€¦  · Web viewPair Programming ProjectPair Programming Project. Pair Programming Project. Pair Programming Project. Table of Contents. program1.py

Example output:

Agree on a theme for your game and then start coding it.

Your theme could include one of the following or anything else.

Space adventure Police adventure Save the world Underwater adventure Prison escape Escape from school Holiday adventure

Pair Programming Project | Challenge 3 16