Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lesson 1 Learning Objectives

Similar presentations


Presentation on theme: "Lesson 1 Learning Objectives"— Presentation transcript:

1 Lesson 1 Learning Objectives
To understand: Variables – how they work and are created To be able to: Setup variables and allow a user to create input to a program

2 Learning Objectives Starter Task: You are learning to program.
What is programming and why is it important to learn how to program? Answer your questions on a word document and discuss your ideas. Learning Objectives To understand: Variables – how they work and are created To be able to: Setup variables and allow a user to create input to a program Key Words IDLE Function Program Code

3 Why should we learn to program?
YouTube video to go here.

4 IDLE Function Program Code
The Python IDLE Load It up – you should see a screen like the one shown – this is the Python Shell IDLE stands for “Integrated Development Environment” – it is the place where a set of tools have been created that allow us to code. Learning Objectives To understand: Variables – how they work and are created To be able to: Setup variables and allow a user to create input to a program Key Words IDLE Function Program Code

5 IDLE Function Program Code
The Python IDLE Type in the following print(“Game Over”) Then press enter Game Over You have just written your first Python program – well done Learning Objectives To understand: Variables – how they work and are created To be able to: Setup variables and allow a user to create input to a program Key Words IDLE Function Program Code

6 IDLE Function Program Code
Task 1 Try the following programs Print (“Game Over”) PRINT (“Game Over”) print (“Game Over’) print (“Game Over” Why do you think these do not work? Discuss your thoughts with the teacher Learning Objectives To understand: The Python IDLE and how it is used To be able to: Use the IDLE to create a simple program and understand how it worked Key Words IDLE Function Program Code

7 IDLE Function Program Code
Syntax Highlighting Special Python words such as Print are displayed in Purple Strings like “Game Over” are displayed in Green The output or program result – Game Over is displayed in Blue Learning Objectives To understand: Variables – how they work and are created To be able to: Setup variables and allow a user to create input to a program Key Words IDLE Function Program Code

8 IDLE Function Program Code
Python Files When you create a program directly in the Python shell it can be only be used once. You should always create separate Python files that can be saved for use later. Learning Objectives To understand: Variables – how they work and are created To be able to: Setup variables and allow a user to create input to a program Key Words IDLE Function Program Code

9 IDLE Function Program Code
Adding Comments To make your program easier to understand you may wish to add comments to a program - this is easy, you simply use the # key print(“Game Over”) # prints onto screen You will notice that your comments are displayed in red – this is another example of Syntax highlighting Learning Objectives To understand: Variables – how they work and are created To be able to: Setup variables and allow a user to create input to a program Key Words IDLE Function Program Code

10 IDLE Function Program Code
Task 3 Main Name program Create a program by open a new Python file. Print out your full name Print out your favourite colour Include a comment Save it in your Python Programming folder as 1.Full name Extension – Use the Python Option menu to configure IDLE further – have a go at the various options available Learning Objectives To understand: Variables – how they work and are created To be able to: Setup variables and allow a user to create input to a program Key Words IDLE Function Program Code

11 Understanding Variables
A variable is a way of labelling and accessing information from a stored location. In the example ‘name’ is the variable. ‘Larry’ is a string that has been assigned to the variable. Changing Larry changes the variable but ‘name’ remains the same. Learning Objectives To understand: Variables – how they work and are created To be able to: Setup variables and allow a user to create input to a program

12 Getting User Input If we create the variable as an Input there is a lot more we can do with it. Copy the code shown into a new Python file. Save it as 1.personal greeter Extension Try to add more questions into your program to find out information about someone. Learning Objectives To understand: Variables – how they work and are created To be able to: Setup variables and allow a user to create input to a program

13 secondLine = "That tonight's gonna be a good, good night."
Extension work Line Breaks / New Lines You can also write your string over several lines by using “\n”. Like this: firstLine = "I got a feeling,\nThat tonight's gonna be a good night.\n" secondLine = "That tonight's gonna be a good, good night." print(firstLine + secondLine) Try writing a few of your own! Learning Objectives To understand: Variables – how they work and are created To be able to: Setup variables and allow a user to create input to a program

14 Lesson 2

15 IDLE Function Program Code
Starter task On your post it note try to explain the what is meant by: A variable A String Learning Objectives To understand what an integer is. To be able to create Python programs that make use of integers. Key Words IDLE Function Program Code

16 Open Python > IDLE (python GUI)
Exercise 1  Try typing each of the following at the command prompt: (press Enter after each 1).  2+2 17-9 16/4 3*7 Learning Objectives To understand what an integer is. To be able to create Python programs that make use of integers.

17 number1 = input("Please enter a number between 1 & 100 "))
Using integers Copy the code below. number1 = input("Please enter a number between 1 & 100 ")) number2 = input("Please enter a number between 1 & 100 ")) print ("number 1 + number 2 =",number1+number2) Save your program as 2.Adding. Can you spot what has gone wrong? Learning Objectives To understand what an integer is. To be able to create Python programs that make use of integers.

18 number1 = int(input("Please enter a number between 1 & 100 "))
Using integers Integers are essentially whole numbers. Copy the code below. number1 = int(input("Please enter a number between 1 & 100 ")) number2 = int(input("Please enter a number between 1 & 100 ")) print ("number 1 + number 2 =",number1+number2) Now edit your program so that it treats the data as integers. By putting int( at the front of the input command we are telling Python we want it treat the data as a whole number and not a String(text). For each set of brackets you have opened you must close the same amount at the of the line. Learning Objectives To understand what an integer is. To be able to create Python programs that make use of integers.

19 Learning Objectives Using integers – Task Subtraction
Edit your code to make it subtract the two numbers. Save it as “2.subtraction” and test it works. Multiplication Edit your code to make it multiply the two numbers. Save it as “multiplication” and test it works Division Edit your code to make it divide the two numbers. Save it as “division” and test it works. Mod Edit your code to make it calculate the modulus (remainder) of a division. Save it as “mod.py” and test it works. (Hint: use x%y) Square Edit your code to make it calculate x2. Save it as “square” and test it works. Learning Objectives To understand what an integer is. To be able to create Python programs that make use of integers.

20 Learning Objectives Using integers – Task 2
Order of Operations / BIDMAS · Brackets · Indices (powers) · Division and Multiplication. Start on the left and work them out in the order that you find them. · Addition and Subtraction. When only addition and subtraction are left in the sum work them out in the order you find them. starting from the left of the sum and working towards the right Try writing a program that will take a number, multiply by three and then add four. Try writing a program that will take a number, add four and then multiply by three. Put the number 7 into both programs and check that they work correctly. Learning Objectives To understand what an integer is. To be able to create Python programs that make use of integers.

21 Lesson 3 Learning Objectives
To understand what a selection means in programming . To be able to create Python programs that make use of IF statements.

22 IDLE Selection IF statement Code
Starter task Spot the error in the code on your piece of paper. There are 5 in total. Learning Objectives To understand what a selection means in programming . To be able to create Python programs that make use of IF statements. Key Words IDLE Selection IF statement Code

23 IDLE Selection IF statement Code
Selection means selecting (or choosing) what to do next. Should I cycle to school, or ask for a lift? If it’s a sunny day I might cycle. If it’s raining, I’ll ask for a lift. Learning Objectives To understand what a selection means in programming . To be able to create Python programs that make use of IF statements. Key Words IDLE Selection IF statement Code

24 Learning Objectives IF ... ELSE
Create a new file and type in the following code, Save it as 3.IF: hours = int(input(“How many hours a day do you play computer games? “)) if hours < 2: print(“That seems a fairly healthy balance. Well done!”) else: print(“You’re probably good enough by now with all that practice.”) There are a number of key points here: Notice how the colon (:) is used to say what should happen in each case. Also notice that the indentation is VERY important. Python only knows when your IF statement is finished by looking at the indentation! Learning Objectives To understand what an integer is. To be able to create Python programs that make use of integers.

25 IF ... ELIF ... ELSE Sometimes there are more than two options: I could walk OR cycle OR get the bus OR get a lift. As well as IF and ELSE, we can stick an ‘ELSE IF’ (or ELIF) in the middle: Create a new file and type in the following code, save it 3.ELIF: hours = int(input(“How many hours a day do you play computer games? “)) if hours < 2: print(“That seems a fairly healthy balance. Well done!”) elif hours < 4: print(“You’re probably good enough by now with all that practice.”) else: print(“Put the controller down and get some fresh air once in a while!”) Learning Objectives To understand what an integer is. To be able to create Python programs that make use of integers.

26 There are a couple of important bits here:
IF ... ELIF ... ELIF ... ELIF ... ELSE You can include an unlimited number of ELIFs if you need to. Try the following: menu = "What would you like a quote about:\n\ 1. Ability\n\ 2. Boredom\n\ 3. Cats?\n\ 9. Quit\n“ choice = int(input(menu)) if choice == 1: print("Great ability develops and reveals itself increasingly with every new assignment.\n Baltasar”) elif choice == 2: print("The secret of being boring is to say everything.\n Voltaire") elif choice == 3: print("Cats regard people as warmblooded furniture.\n Jacquelyn Mitchard") elif choice == 9: print("Goodbye!!!") There are a couple of important bits here: You can put a line break in your string by using “\n”. You can continue a line of code by putting a “\” at the end. If you are testing for equality, use a double equals (is 3x2 = = 6?) Make your own program that uses a menu system and give the user a response


Download ppt "Lesson 1 Learning Objectives"

Similar presentations


Ads by Google