python magic
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 PresentationTRANSCRIPT
Select a Lesson:
» Why Learn to Code?
» Basic Python Syntax
» A Simple Calculator
» Guess the Number
» Fantastic Functions
» Secret Messages
» Adventure Game
Why should we learn to program?
Basic Python Syntax
LEARNING OBJECTIVE
Understand and be able to use basic Python syntax.
VARIABLES
The way we store data.
String – a type of variable for storing text “strings”.
Enter the code shown here to create your first computer
program.
Now let’s add to that . . .
What do you think this will do?
YOUR TASK
Add to your program so you can have a
conversation with the computer (stick to yes and no answers
for now!)
NEXT TASK
Create an account at www.codecademy.comComplete the first
Python course called ‘Python Syntax’
LEARNING OBJECTIVE
Understand and be able to use basic Python syntax.
or
Calculator
LEARNING OBJECTIVE
Understand how to use selection to create a simple calculator.
VARIABLES
String – remember this from last lesson?
Numbers:Integer Float
What’s happening here ?
SELECTION
How we choose a suitable action based on a condition.
IF I’m hungryEat Something
ELSEDon’t eat anything
Can you add more selection to handle multiplication and
division ?
NEXT TASK
Log onto www.codecademy.comand continue the
Python course from where you finished
last lesson.
LEARNING OBJECTIVE
Understand how to use selection to create a simple
calculator.
or
Loopy Loops
LEARNING OBJECTIVE
Understand how to create a loop in Python and use a
Boolean variable to define when to stop.
ANOTHER VARIABLE
Boolean – This can store one of two values:
True False
LOOPS
A While loop can keep looping through events until
a condition changes.
WHILE hungry == TrueKeep eatingIF I’m full uphungry == False
Have a go at this ‘Guess the Number’ game. What does
each part do?
LEARNING OBJECTIVE
Understand how to create a loop in Python and use a Boolean variable to define when to stop.
or
Fantastic Functions
LEARNING OBJECTIVE
Understand how to use and call functions.
WHAT IS A FUNCTION?
A block of code grouped together that
can be run at any point in our program.
Try creating this function to pull a rabbit from a hat! Don’t forget the magic word though!
Try out this function. What does that bit in brackets do?
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.
You should have added something like this to the end
of your program.
NEXT TASK
Log onto www.codecademy.comand continue the
Python course from where you finished
last lesson.
Secret Messages
LEARNING OBJECTIVE
Understand how to store and look up
values from a list.
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.
Here’s a list of students. What will each print statement do?
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!
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. . .
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.
Can you decode this secret message?
s vyfo mywzedob zbyqbkwwsxq
Are there any clues to help us work out the shift number?
What is happening here?Create your own encryption
program and test it out.
Text Adventure
s
LEARNING OBJECTIVE
Recognise how a class can be used to create
custom objects.
CLASSES
A custom object that you can make that has
it’s own set of attributes.
Animal Class
Giraffe Horse Lion
TASK
Open and look at the Animals.py example from
SharePoint.
Can you figure out what some of the bits of code
are doing?
Underneath the class create a new ‘instance’ of an animal and give it some attributes. You can choose any animal
you like.
TASK
Use the design sheet to plan your own text adventure then follow the instructions to
create this in Python.
LEARNING OBJECTIVE
Recognise how a class can be used to create
custom objects.