700 likes | 1.57k Views
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
E N D
Select a Lesson: • Why Learn to Code? • Basic Python Syntax • A Simple Calculator • Guess the Number • Fantastic Functions • Secret Messages • Adventure Game Python Magic
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.
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.com Complete the first Python course called ‘Python Syntax’
Understand how to use selection to create a simple calculator.
VARIABLES String – remember this from last lesson? Numbers: Integer Float
SELECTION How we choose a suitable action based on a condition. IF I’m hungry Eat Something ELSE Don’t eat anything
Can you add more selection to handle multiplication and division ?
NEXT TASK Log onto www.codecademy.com and continue the Python course from where you finished last lesson.
Understand how to use selection to create a simple calculator. or
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 == True Keep eating IF I’mfull up hungry == False
Have a go at this ‘Guess the Number’ game. What does each part do?
Understand how to create a loop in Python and use a Boolean variable to define when to stop. or
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!
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.com and continue the Python course from where you finished last lesson.
LIST (Also known as an array) A way of storing more than one thing under one variable name. My magic potion contains hair, knotgrassand 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 vyfomywzedobzbyqbkwwsxq 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.
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.