LAB
Objectives
Scenario
Using one of the comparison operators in Python, write a simple two-line program that takes the parameter n as input, which is an integer, and prints False if n is less then 100, and True if n is greater than or equal to 100.
Don't create any if blocks (we're going to talk about them very soon). Test your code using the data we've provided for you.
Conditions and conditional execution
You already know how to ask Python questions, but you still don't know how to make reasonable use of the answers. You have to have a mechanism which will allow you to do something if a condition is met, and not do it if it isn't.
It's just like in real life: you do certain things or you don't when a specific condition is met or not, e.g., you go for a walk if the weather is good, or stay home if it's wet and cold
To make such decisions, Python offers a special instruction. Due to its nature and its application, it's called a conditional instruction (or conditional statement).
There are several variants of it. We'll start with the simplest, increasing the difficulty slowly.
The first form of conditional statement, which you can see below is written very informally but figuratively:
if true_or_not:
do_this_if_true
This conditional statement consists of the following, strictly necessary, elements in this and this order only:
How does the that statement work?
In real life, we often express desire:
if the weather is good, we'll go for a walk
then, we'll have lunch
As you can see, having lunch is not a conditional activity and doesn't depend on the weather.
Knowing what conditions influence our behavior, and assuming that we have the parameterless functions go_for_a_walk() and have_lunch(), we can write the following snippet:
if the_weather_is_good:
go_for_a_walk()
have_lunch()