Presentation is loading. Please wait.

Presentation is loading. Please wait.

An Introduction to Textual Programming

Similar presentations


Presentation on theme: "An Introduction to Textual Programming"— Presentation transcript:

1 An Introduction to Textual Programming
KS3 Python An Introduction to Textual Programming

2 Python 1 Todays objectives: Use the Print function Store Variables
Create a conversation Carry out calculations

3 Getting Started Open your Unit 2 Programming folder
Create another folder called “Python Practice” This is where you are going to save all your Python practice work!

4 The Basics Open IDLE (Python GUI) Click File  New Window
This allows you to write code, which is checked line by line as you write it. Click File  New Window This allows you to write full programs and then run them. If you make a mistake you will not know until you run it.

5 Before we start Spelling and Capital letters are essential in Python!!!! 1 missed capital letter and your program may not work. Make notes in your exercise books, this will help you later!

6 Text

7 Open Python Now open Python. Type print (“Hello World”) Press enter
Welcome to Programming! FYI: In programming text is knows as a string. Strings include all letters, numbers and characters.

8 User Input Now lets get the user to input some text:
Type: input (“What is your name”) What happens? What would make it neater? Code What is does \n Goes to a new line \t Creates a tab indent

9 Useful Code What is does \n Goes to a new line \t Creates a tab indent

10 Manipulating Strings Method Description Example capitalize()
Changes the strings first letter to upercase string.capitalize() upper() changes the string to all uppercase letters string.upper() lower() changes the string to all lowercase letters string.lower() replace(old, new) replaces a letter with another letter string.replace (‘o’, ‘*’) count(x) returns the number of occurrences of x string.count(‘o’) find(x) finds the index of the first occurrence of x or -1 if its not found. string.find (‘o’) isalpha() Returns true ii string is all letters string.isalpha() isnumeric() Returns true ii string is all numbers string.isnumeric()

11 Variables You learned about variables in Scratch.
You can assign variables in a similar way in Python. Try: name = input (“Please enter your name: \n”) print (“Hello”, name) Try asking more questions and setting variables. Can you create a conversation? What do you notice about using text? Do you have to put “ “ around variables?

12 MAths

13 Try These 8*7 10253/565 “Hello ” * 3

14 Lesson 2

15 Variables Remember you can think of a variable as being a container where you can store data or a value for use later. You can choose virtually any name for a variable, except for protected words. Ways of storing a variable: A = 8 Try : A*A a,b,c = 1,2,3 Try: a+b+c

16 Good To Know If you set a variable you can change the variable like this: a = 9 a = (So now a = 10) a = a + 1 (Again a = 10)

17 NEED TO KNOW There are different types of numbers that you can use in python. We are going to look at integers. Integer: A whole number, not a fraction To convert something x to an integer, type the following: int(x) If you ask the user for input it will automatically be a string so you will need to convert it to an integer. Best way: no = int (input (“Please enter a number: \t”)) no will be an integer!

18 Logic: Think How could you write the code to ask the user for a number and then multiply the number by 10? Write a program to ask the user for a number and multiply it by 10. DON’T USE THE SHELL  Press File, New

19 Try converting Ask the user for a number: Set the number as a variable
Then multiply their number by 5.

20 Now you have the basics lets start programming

21 First Program Now lets write our first proper program.
Click File  New This will open up a new window This is where you will write your code. Press F5 to run your code. You must save the work in your H Drive  Python Practice Folder

22 Don’t forget to convert the input to an integer.
Task Write a program to ask a user for a number of hours and then convert it to minutes. How can you convert from hours to minutes? Save it as “Hour to Minute Convertor” Extension: Create other conversion programs: Miles to Kilometres Feet to Meters Years to days Years to minutes Or anything else you think might be useful. Don’t forget to convert the input to an integer.

23 Lesson 3

24 Reminder print (“Hello World”) input (“What is your name”)
name = input (“Please enter your name: \n) print (“Hello”, name) A = 8 no = int (input (“Please enter a number: \t”)) int(x)

25 IF Statements What can you remember from IF statements from Scratch?
Its very similar in Python.

26 If Else if expression: statement(s) else:

27 Try it. Write a program which asks the user for a number between 1 and 10 and then tells them if it is over 5 or under 5. Save your program

28 Lesson 4

29 IF ELIF ELSE What happens if you want to check more than one situation. E.G: If you wanted to calculate if someone was a child, teenager, or Adult. IF ELIF and ELSE can be used for this.

30 IF, ELIF, ElSE if expression1: statement(s) elif expression2: elif expression3: else:

31 Try it Write a program to say whether a person is a child, teenager, or adult. If they are over 18 they are an adult If they are under 13 they are a child Otherwise they are a teenager

32 The Code

33 While

34 While Loop

35 Try it From 10 count to 50 using a while loop. Advanced:
Ask the user for the start number Ask the user for the last number Print the list of numbers You could ask the what jumps they want to go up to. E.G: Count in 10s up to 100.

36 Assessment

37 Assessment Level 3: Make something happen by writing your own set of instructions Level 4: Create a set of instructions for a programme, and improve your instructions to make the programme more efficient Level 5: Create precise and accurate sequences of instructions

38 Assessment You must create an original game. The game will be in the format of a quiz. The way the game looks and works will be completely up to you. Your game will have the following; Ask the users name and use this in the quiz At least 3 questions A scoring system At the end of the game it will say the users score Your game might include: An introduction to the quiz Anything else you think would improve the game!

39 Can you put together what you learned to create a game.
Last Python Lesson

40 Random Function Create a game where the computer will generate a random number and the user will try and guess the number. The game will feedback if the guess is too high or too low. You will need to use the while or for loop to get the game to keep running.

41 Random

42 Random Function Create a game where the computer will generate a random number and the user will try and guess the number. The game will feedback if the guess is too high or too low. You will need to use the while or for loop to get the game to keep running.

43 Guessing Game Set a variable as a random number
Ask the user to enter a number and save as a variable. If the user number is smaller than the computer number then say its to small. If its too big say its too big. If they are the same say the got it.


Download ppt "An Introduction to Textual Programming"

Similar presentations


Ads by Google