python magic

51
Select a Lesson: » Why Learn to Code? » Basic Python Syntax » A Simple Calculator » Guess the Number » Fantastic Functions » Secret Messages » Adventure Game

Upload: alpha

Post on 23-Feb-2016

85 views

Category:

Documents


1 download

DESCRIPTION

Select a Lesson: Why Learn to Code? Basic Python Syntax A Simple Calculator Guess the Number Fantastic Functions Secret Messages Adventure Game. Python Magic. Why should we learn to program?. Basic Python Syntax. Understand and be able to use basic Python syntax . VARIABLES - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Python Magic

Select a Lesson:

» Why Learn to Code?

» Basic Python Syntax

» A Simple Calculator

» Guess the Number

» Fantastic Functions

» Secret Messages

» Adventure Game

Page 2: Python Magic

Why should we learn to program?

Page 3: Python Magic

Basic Python Syntax

Page 4: Python Magic

LEARNING OBJECTIVE

Understand and be able to use basic Python syntax.

Page 5: Python Magic

VARIABLES

The way we store data.

String – a type of variable for storing text “strings”.

Page 6: Python Magic

Enter the code shown here to create your first computer

program.

Page 7: Python Magic

Now let’s add to that . . .

Page 8: Python Magic

What do you think this will do?

Page 9: Python Magic

YOUR TASK

Add to your program so you can have a

conversation with the computer (stick to yes and no answers

for now!)

Page 10: Python Magic

NEXT TASK

Create an account at www.codecademy.comComplete the first

Python course called ‘Python Syntax’

Page 11: Python Magic

LEARNING OBJECTIVE

Understand and be able to use basic Python syntax.

or

Page 12: Python Magic

Calculator

Page 13: Python Magic

LEARNING OBJECTIVE

Understand how to use selection to create a simple calculator.

Page 14: Python Magic

VARIABLES

String – remember this from last lesson?

Numbers:Integer Float

Page 15: Python Magic

What’s happening here ?

Page 16: Python Magic

SELECTION

How we choose a suitable action based on a condition.

IF I’m hungryEat Something

ELSEDon’t eat anything

Page 17: Python Magic

Can you add more selection to handle multiplication and

division ?

Page 18: Python Magic

NEXT TASK

Log onto www.codecademy.comand continue the

Python course from where you finished

last lesson.

Page 19: Python Magic

LEARNING OBJECTIVE

Understand how to use selection to create a simple

calculator.

or

Page 20: Python Magic

Loopy Loops

Page 21: Python Magic

LEARNING OBJECTIVE

Understand how to create a loop in Python and use a

Boolean variable to define when to stop.

Page 22: Python Magic

ANOTHER VARIABLE

Boolean – This can store one of two values:

True False

Page 23: Python Magic

LOOPS

A While loop can keep looping through events until

a condition changes.

WHILE hungry == TrueKeep eatingIF I’m full uphungry == False

Page 24: Python Magic

Have a go at this ‘Guess the Number’ game. What does

each part do?

Page 25: Python Magic

LEARNING OBJECTIVE

Understand how to create a loop in Python and use a Boolean variable to define when to stop.

or

Page 26: Python Magic

Fantastic Functions

Page 27: Python Magic

LEARNING OBJECTIVE

Understand how to use and call functions.

Page 28: Python Magic

WHAT IS A FUNCTION?

A block of code grouped together that

can be run at any point in our program.

Page 29: Python Magic

Try creating this function to pull a rabbit from a hat! Don’t forget the magic word though!

Page 30: Python Magic

Try out this function. What does that bit in brackets do?

Page 31: Python Magic

YOUR CHALLENGE

Add to your program so it tells the user

whether or not their word is a palindrome.

Hint: try using an if statement to compare the original word with

the reversed word.

Page 32: Python Magic

You should have added something like this to the end

of your program.

Page 33: Python Magic

NEXT TASK

Log onto www.codecademy.comand continue the

Python course from where you finished

last lesson.

Page 34: Python Magic

Secret Messages

Page 35: Python Magic

LEARNING OBJECTIVE

Understand how to store and look up

values from a list.

Page 36: Python Magic

LIST(Also known as an array)

A way of storing more than one thing under one

variable name.

My magic potion contains hair, knotgrass and

leeches.

Page 37: Python Magic

Here’s a list of students. What will each print statement do?

Page 38: Python Magic

Another way to add items is using the ‘append’ command. Use this

to add some more students.

Make sure you print your list of students again to make sure

your code has worked!

Page 39: Python Magic

CAESAR SHIFT

A well-known cipher to encode a piece of text by replacing one letter of the alphabet

with another a chosen number of places (shifts).

For example, a shift of 2 means “A” becomes “C”:

A B C D E F G H I K L. . .

Page 40: Python Magic

TASK

Cut out and make your own Caesar Cipher Wheel using

your worksheet.

Use your wheel to create a secret message for the person next to you to

decode.

Page 41: Python Magic

Can you decode this secret message?

s vyfo mywzedob zbyqbkwwsxq

Are there any clues to help us work out the shift number?

Page 42: Python Magic

What is happening here?Create your own encryption

program and test it out.

Page 43: Python Magic

Text Adventure

s

Page 44: Python Magic

LEARNING OBJECTIVE

Recognise how a class can be used to create

custom objects.

Page 45: Python Magic

CLASSES

A custom object that you can make that has

it’s own set of attributes.

Page 46: Python Magic

Animal Class

Giraffe Horse Lion

Page 47: Python Magic

TASK

Open and look at the Animals.py example from

SharePoint.

Can you figure out what some of the bits of code

are doing?

Page 48: Python Magic

Underneath the class create a new ‘instance’ of an animal and give it some attributes. You can choose any animal

you like.

Page 49: Python Magic
Page 50: Python Magic

TASK

Use the design sheet to plan your own text adventure then follow the instructions to

create this in Python.

Page 51: Python Magic

LEARNING OBJECTIVE

Recognise how a class can be used to create

custom objects.