Download presentation
Presentation is loading. Please wait.
Published byOwen Underwood Modified over 9 years ago
1
Python Programming Using Variables and input
2
Objectives We’re learning to make use of if statements to enable code to ask questions. Outcomes Build an if statement Include commenting and syntax Continue the use of parameters
3
Function - Starter Write two functions: 1.Ask for input of two numbers and add them together. 2.Ask for your name and age using parameters.
4
Time to call the operator? Operators Before you can start learning about an IF STATEMENT you will need to know about operators. Operators help us compare or check values. We can add, divide and even use mathematical equations such as ‘to the power of’. The next slides will explain some of these.
5
Operators What you may need in an IF STATEMENT Most Used +Add to -Subtract *Multiply /Divide Comparisons != Not equal to > Greater than < Less than >= Greater than or equal to <=Less than or equal to & Logical and
6
What is an IF STATEMENT? An IF statement checks to see if a statement is true or false and then does one of two things depending on the result. It looks like this in Excel. =IF(Condition check,Do this if true, Do this if false) We’re not using Excel, we’re using python…. Lets break this down.
7
Building the If Statement? For this task, we’re going to start off by setting up a function and testing a name. Use this code.
8
Run the code? This is what should happen! See if you can write a Function with parameters in the statement. You have 5 minutes to complete this.
9
What Else? Have a look at this script…. Spot the difference from your previous code.
10
Lets get to work! You’ve seen how to build an if statement using text input. Lets build some functions with parameters and If Functions. Here is an example of one: - Spot anything new?
11
Tasks ? Write the following functions to use ifstatements, parameters and operators: 1.Test a number to see if it’s greater than or equal to 10 and display a message. 2.Test a name to see if it’s equal to ‘robert’ and say hello to that person. 3.Write a multiple if statemented function which includes a test for 2 different peoples names. 4.Extension – See if you can figure out how to test two different numbers within the function at the same time. Answer in Teacher Notes
12
Plenary Self Assessment: Your teacher has issued you with a self assessment sheet. You will have today’s objects and outcomes on it. Task Comment on the lesson. Talk about the positive experience you have had and talk about things you need a little more help on. If you managed to get onto the extension tasks, what have you found out?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.