Python - Variables and Data types
Set your Learning Objectives to red.
Open your PowerPoint from last lesson.
If for any reason you cannot open Thonny then click on the link below to use an online version of Python called CodeSkulptor3. Just be aware that the lessons are based upon using python in Thonny however the code will be exactly the same.
You have two python options for completing todays lesson.
In class we are going to be using the Python tool called 'Thonny' This is an app on your computer so search for it in the search bar
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 =.
Last week we learned that In python if you want the user to input data into the program, you can use the input()function, this is another built in functions to help us put data into our program.
...In order to get user input in python you need to use the input() function. This puts a prompt onto the screen to allow the user to enter data. If you want to use the data in your program you have to store it in a variable . The print function can then use the variable to output our user input to the screen .
Let's change the code from the previous task and rather than write Weather = "Raining" instead use an input() to get the weather from the user.
Change the code above so it uses an input to get the input() to get the weather from the user.
Save the file name as 'selection2'.
Run the code.
Remember to use correct 'Indentation'
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
Don't forget to turn the user input() into an integer using the int() function.
Explain your answers in your Powerpoint next to a screenshot of your code
The text below shows how to add in an else for the previous activity.
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.
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