Conditions

A condition is an expression that can be evaluated as either True or False. This is done using comparison operators, logical operators, and Booleans.
Comparison Operators
== equal to
!= not equal to
> greater than
< less than
>= greater than or equal to
<= less than or equal to
For example, the expression 15 < 20 would be True because 15 is indeed less than 20, and "hello" == "goodbye" would be False because the phrases "hello" and "goodbye" are not the same.
Logical operators can be used to make complex expressions. There are three logical operators:
  • and - combines two expressions where both must be True
  • or - combines two expressions where either must be True
  • not - turns an expression from True to False and vice versa
Booleans are another type of variable that can have one of two values, either True or False. The name Boolean comes from the English mathematician George Boole, who did work in the field of logic.

Exercise 1 of 9

Which of the following conditions represents the statement: It costs less than 10 dollars

Exercise 2 of 9

Which of the following conditions represents the statement: There are 12 ducks in the pond

Exercise 3 of 9

Which of the following conditions represents the statement: He is not old

Exercise 4 of 9

Write a condition to represent the statement: x is less than or equal to 12

Your answer

Exercise 5 of 9

Write a condition to represent the statement: age is at least 45

Your answer

Exercise 6 of 9

Write a condition to represent the statement: y is not 3

Your answer

Exercise 7 of 9

Write a condition to represent the statement: age is greater than 16 and height is greater than 60

Your answer

Exercise 8 of 9

Write a condition to represent the statement: x is either greater than 50 or less than 25

Your answer

Exercise 9 of 9

Write a condition using the keyword not to represent the statement: running is False

Your answer