Python - Variables and Data types
Set your Learning Objectives to red.
Open your PowerPoint from last lesson.
In Python The 'if' statement is used to conditionally execute a statement. In other words we look at a statement(conditional) and decide if that conditional statement is true or false,we then do one thing when the condition is true and something else when the condition is false.
Lets see if we can create a version of the above flowchart in python.
Notice how when we compare if things are equal in python we use == not a single =.
In python when we compare two or more data values or identifiers we have to use comparison operators.
These are mathmatical symbols like ==, >=, < etc.
This allows us to determine if the comparison we are making is True or False
These are called conditional statements in python because they determine if a condtion is True or False.
A conditional statement is any statement that can be determined to be True or False. To make a statement conditional we use comparison operators
Complete the code below you can find a link to it on codeskulptor by clicking here
We use conditional statements in a python if statement.
Look at the conditional statement in the diamond below, should we DO THIS or DO THAT?
What about this next one, should we DO THIS or DO THAT?
Copy the text below into a Python file and run it to see what happens
Can you change the conditional operator so that it doesn't print anything out at all?
Explain your answers in your Powerpoint next to a screenshot of your code
Can you change the condition to check if the two numbers are the same and print out suitable statements?
Sometimes we want to have more that two opions when we make a choice we can do that in python by using an elif statement.
1. Can you change the code so that the user inputs a number and you then print out whether it is small medium big or huge?
2. Can you develop the code so that the user can input their favourite colour and you then print out something about the colour they chose?
Tick each task when you have successfully done it in the following list:
Lets look at the learning outcomes and decide which one best describes our current level of understanding :
Tick the one you feel is closest to your level