Lecture 1 - Conditionals Flashcards

1
Q

Allows the programmer, to allow your program to make decisions based upon certain conditions.

A

Conditionals

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Used to ask mathematical questions

A

Operators

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Denotes “greater than or equal to.”

A

> =

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Denotes “less than or equal to.”

A

<=

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Denotes “equals”, used to compare variables.

A

==

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Denotes “not equal to.

A

!=

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

This kind of statement uses bool or boolean values (true or false) to decide whether or not to execute.

A

If

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

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.

A

Elif

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Elif Syntax

A

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”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Statements that catches anything which isn’t caught by the preceding conditions.

A

Else

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Else Syntax

A

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”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

This conditional allows your program to decide between one or more alternatives.

A

Or

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Or Syntax

A

if x < y or x > y:
print(“x is not equal to y”)

else:
print(“x is equal to y”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Is a logical operator, and is used to combine conditional statements

A

And

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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.

A

Match Case

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Match Case Syntax

A

> > > command = ‘Hello, World!’

> > > match command:
… case ‘Hello, World!’:
… print(‘Hello to you too!’)
… case ‘Goodbye, World!’:
… print(‘See you later’)
… case other:
… print(‘No match found’)

Hello to you too!

17
Q

This will match with any input, resulting in similar behavior as an else statement.

A

_ Symbol

18
Q

_ Symbol Syntax

A

match name:
case “Harry”:
print(“Gryffindor”)
case “Hermione”:
print(“Gryffindor”)
case “Ron”:
print(“Gryffindor”)
case “Draco”:
print(“Slytherin”)
case _:
print(“Who?”)

19
Q

A match statement compares the value following the match keyword with each of the values following the ____ keywords

A

Case

20
Q

Case Syntax

A

match name:
case “Harry” | “Hermione” | “Ron”:
print(“Gryffindor”)
case “Draco”:
print(“Slytherin”)
case _:
print(“Who?”)

21
Q

Much like the or keyword, this allows us to check for multiple values in the same case statement.

A

Single | bar

22
Q

Single | Syntax

A

match name:
case “Harry” | “Hermione” | “Ron”:
print(“Gryffindor”)