One more fundamental feature of computer programs is comparison. Comparing things is fundamental to making decisions about what to do next or how many times you want a particular operation to execute.
We are learning ...
So that we can ...
Task 1.1 Your own decision problems
Where we learn about decision problems (which have 'yes' or 'no' answers)
What do the answers to the following questions have in common?
Write down five of your own decision problems in your notebooks. Remember, decision problems always, and only have 'Yes' or 'No' answers which a computer would struggle to give.
Task 1.2 Your own decision statements
Where we learn about decision statements (which have 'true' or 'false' answers)
It's also possible to rephrase these questions into decision statements which have 'True / False' responses. Technically, decision statements do not have 'answers' - they are either 'True' or 'False' which is a standard Boolean datatype which computers are very comfortable handling.
Rephrase the questions you came up with in Task 1.1 as statements with either 'True' or 'False' responses. Write down the statements in your notebooks.
Just like the mathematical operators we met in a previous unit, there are some issues with the standard mathematical comparison operators we are used to using.
Task 2.1 Spot the operator
Where we learn about the built in comparison operators that can be typed directly at the keyboard
Look carefully at the following list of comparison operators ...
Like we did during a previous unit, look for the 'Not equal to', 'Greater than or equal to' and 'Less than or equal to' symbols on your computer keyboard. Can you find them? Yes, but it means something different in Python! Combinations of symbols are used for these comparison operators ...
Hang on, the 'Equal to' symbol is also in orange! Remember that the equals sign (=) is already used for assignment and therefore, we can't use it for comparison. So ...
Make a full list of the programming comparison operators (in blue) and explain the function each one of them performs.
Task 2.2 Testing them out Where we learn how Python behaves when we give it decision statements
This task requires you to carry out some comparison operations at the prompt. There is no need to record any of the interactions with Python, but make sure you write about what you have found out.
Type in the following Python comparison statements, pressing the ENTER key after each one. Convince yourself that the comparison statements produce the expected output (the output that makes sense).
>>> 12 == 9 >>> 12 > 9 >>> 12 < 9 >>> 12 >= 9 >>> 12 <= 9 >>> 12 != 9 ... and now with variables (there is no need to type the comments) ... >>> shoes = 12 # this is an assignment and produces no output, so don't expect one! >>> feet = 12 # this is an assignment and produces no output, so don't expect one! >>> shoes == feet >>> shoes != feet >>> shoes > feet >>> shoes < feet >>> shoes >= feet >>> shoes <= feet Combining multiple decision statements with AND, OR and NOT Write about what have you found out from this task using some of the Python statements to help you with your explanation. What output do these kind of programming statements always produce?
Try out the True Or False quiz at the Merriam-Webster dictionary website! Really, even though this is an 'I am hungry and I want to learn more' activity, I'll probably make you do it anyway cause it's nice. |