Loading [MathJax]/jax/output/HTML-CSS/fonts/TeX/fontdata.js

Comparison operators: greater than

You can also ask a comparison question using the > (greater than) operator. 

If you want to know if there are more black sheep than white ones, you can write it as follows: 

black_sheep > white_sheep # Greater than

True confirms it; False denies it

Comparison operators: greater than or equal to

The greater than  operator has another special, non-strict variant, but it's denoted differently than in classical arithmetic notation: >= (greater than or equal to).

There are two subsequent signs, not one. 

Both of these operators (strict and non-strict), as well as the two others discussed in the net section, are binary operators with left-sided binding,  and their priority is greater than that shown by == and !=

If we want to find out whether or not we have to wear a warm hat, we ask the following question:

centigrade_outside ≥ 0.0 # Greater than or equal to 

Comparison operators: less than or equal to

As you've probably already guessed, the operators used in this case are: the < (less than) operator and its non-strict sibling: <= (less than or equal to).

Look at this simple example: 

current_velocity_mph < 85 # Less than
current_velocity_mph ≤ 85 # Less than or equal to

We're going to check if there's risk of being fined by the highway police (the first question is strict, the second isn't)

Making use of athe answers

What can you do with the answer (i.e., the result of a comparison operation) you get from the computer?

The content of the variable will tell you the answer to the question asked. 

The second possibility is more convenient and far more commo: you can use the answer you get to make a decision about the future of the program.

You need a special instruction for this purpose, and we'll discuss it very soon. 

Now we need to update our priority table, and put all the new operators into it. It now looks as follows:

 

PriorityOperator

1+, -unary

2**

3*, /, //, %

4+, -binary

5<, <=, >, >=

6==, !=

LAB

Objectives

  • becoming familiar with the input()
  • becoming familiar with comparison operators in Python

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.