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 ...- About the logical methods that computers can use to compare things
So that we can ...- Have practical experience of using standard comparative operations in a programming language
- Equal to / the same as - Not equal to / not the same as - Less than - Less than or equal to - Greater than - Greater than or equal to
Task 1.1 Your own decision problemsWhere we learn about decision problems (which have 'yes' or 'no' answers)
What do the answers to the following
questions have in common?
Yes' or 'No' answers. These sorts of questions are called decision problems - in computer science terms, they are decidable (that really is a word).
In your notebook / on paperWrite 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 statementsWhere 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.
In your notebook / on paperRephrase 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 operatorWhere 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 ...
In your notebook / on paperMake a
full list of the programming comparison operators (in blue) and explain the function each one of them performs.Task 2.2 Testing them outWhere 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.
At the promptType 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 ` `>>> 12 ` `>>> 12 ` `>>> 12 ` `>>> 12 ` `>>> 12 ` ... 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
In your notebooks / on paperWrite 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. |