Lecture 1 - Conditionals Flashcards
Allows the programmer, to allow your program to make decisions based upon certain conditions.
Conditionals
Used to ask mathematical questions
Operators
Denotes “greater than or equal to.”
> =
Denotes “less than or equal to.”
<=
Denotes “equals”, used to compare variables.
==
Denotes “not equal to.
!=
This kind of statement uses bool or boolean values (true or false) to decide whether or not to execute.
If
This kind of statement allows the program to make fewer decisions.
First, the if statement is evaluated. If this statement is found to be true, all the ____ statements will not be run at all.
Elif
Elif Syntax
if x < y:
print(“x is less than y”)
elif x > y:
print(“x is greater than y”)
elif x == y:
print(“x is equal to y”)
Statements that catches anything which isn’t caught by the preceding conditions.
Else
Else Syntax
if b > a:
print(“b is greater than a”)
elif a == b:
print(“a and b are equal”)
else:
print(“a is greater than b”)
This conditional allows your program to decide between one or more alternatives.
Or
Or Syntax
if x < y or x > y:
print(“x is not equal to y”)
else:
print(“x is equal to y”)
Is a logical operator, and is used to combine conditional statements
And
Statements that allows you to more easily control the flow of your programs by executing certain parts of code if conditions (or cases) are met.
Match Case