1 / 51

Python Magic

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

alpha
Download Presentation

Python Magic

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Why should we learn to program?

  3. Basic Python Syntax

  4. Understand and be able to use basic Pythonsyntax.

  5. VARIABLES The way we store data. String – a type of variable for storing text “strings”.

  6. Enter the code shown here to create your first computer program.

  7. Now let’s add to that . . .

  8. What do you think this will do?

  9. YOUR TASK Add to your program so you can have a conversation with the computer (stick to yes and no answers for now!)

  10. NEXT TASK Create an account at www.codecademy.com Complete the first Python course called ‘Python Syntax’

  11. Understand and be able to use basic Pythonsyntax. or

  12. Calculator

  13. Understand how to use selection to create a simple calculator.

  14. VARIABLES String – remember this from last lesson? Numbers: Integer Float

  15. What’s happening here ?

  16. SELECTION How we choose a suitable action based on a condition. IF I’m hungry Eat Something ELSE Don’t eat anything

  17. Can you add more selection to handle multiplication and division ?

  18. NEXT TASK Log onto www.codecademy.com and continue the Python course from where you finished last lesson.

  19. Understand how to use selection to create a simple calculator. or

  20. Loopy Loops

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

  22. ANOTHER VARIABLE Boolean – This can store one of two values: • True • False

  23. LOOPS A While loop can keep looping through events until a condition changes. WHILE hungry == True Keep eating IF I’mfull up hungry == False

  24. Have a go at this ‘Guess the Number’ game. What does each part do?

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

  26. Fantastic Functions

  27. Understand how to use and call functions.

  28. WHAT IS A FUNCTION? A block of code grouped together that can be run at any point in our program.

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

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

  31. 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.

  32. You should have added something like this to the end of your program.

  33. NEXT TASK Log onto www.codecademy.com and continue the Python course from where you finished last lesson.

  34. Secret Messages

  35. Understand how to store and look up values from a list.

  36. 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.

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

  38. 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!

  39. 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. . .

  40. 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.

  41. Can you decode this secret message? s vyfomywzedobzbyqbkwwsxq Are there any clues to help us work out the shift number?

  42. What is happening here? Create your own encryption program and test it out.

  43. Text Adventures

  44. Recognise how a class can be used to create custom objects.

  45. CLASSES A custom object that you can make that has it’s own set of attributes.

  46. Animal Class Giraffe Horse Lion

  47. TASK Open and look at the Animals.py example from SharePoint. Can you figure out what some of the bits of code are doing?

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

  49. TASK Use the design sheet to plan your own text adventure then follow the instructions to create this in Python.

More Related