# In what way is your bodies defense like a medieval caste?

0
0
1. Drawings
320 seconds
Check in- Create a drawing to represent your holiday
2. Slide
60 seconds
Conditional Statements
Lesson 10
3. Slide
60 seconds
4. Slide
60 seconds
Conditional statements are used to execute code based on a condition, such as a variable's value. Python can use a variety of conditional statements, such as if/else, elif, and nested ifs. Conditional statements can also be used with compound logical operators, such as 'and' and 'or'.
Python Conditional Statements
5. Slide
60 seconds
if-else statement: An if-else statement is a programming construct that tests a condition and then runs one block of code if the condition is true and runs another block of code if the condition is false. Nested if-else statement: A nested if-else statement is a programming construct that allows for multiple levels of branching. This means that you can use an if statement within an if statement, which is useful for testing multiple conditions. Logical Operators: Logical operators are used to execute boolean logic, which is the comparison of two values to determine if they are equal, not equal, greater than, less than, and so on.
Concepts:
6. Slide
60 seconds
Display a message if a game player has accumulated a set amount of experience points (variable name of xp). This program will only run if the experience points are greater than or equal to 90. This action will then print out the text “Skill Level: Expert”. If the number of experience points is less than 90, nothing will happen.
Example
7. Slide
60 seconds
8. Slide
60 seconds
This action is possible with an else statement. (An else statement runs when the Boolean value is False.) To use the else statement, type “else” on a new line. Then, on the next line, indent 1 tab and add code that will run if the Boolean expression is false.
What if you want to run code when a statement is false?
9. Slide
60 seconds
10. Slide
60 seconds
One last conditional statement is an elif statement. Elif combines an else statement with another conditional statement to check for additional information. Elif can only be used after an “if” or another “elif” statement. Next to elif, add a Boolean expression and then a colon.
ELIF Statements
11. Slide
60 seconds
12. Slide
60 seconds
13. Drawings
450 seconds
Brain break: Draw a monster made of spaghetti with meatball eyes and noodle arms and legs.
14. Poll
60 seconds
What are the three types of conditional statements in Python?
• if, else, elif
• for, while, do-while
• try, except, finally
15. Poll
60 seconds
What is the symbol used for 'equal to' in Python?
• ==
• =
• ===
• <=
16. Poll
30 seconds
Which of these operators is used for 'not equal to' in Python?
• !=
• <>
• ==!
• >=
17. Slide
60 seconds
Compound Conditional Statements
18. Slide
60 seconds
A compound conditional statement contains two Boolean expressions. Code runs that must meet the conditions as part of the conditional statement. In order to combine these Boolean expressions, we will use logical operators .
Compound Conditional
19. Slide
60 seconds
We use them to check if certain conditions are met before deciding the execution path your programs will follow.
Logical operators
20. Open question
160 seconds
Python has three logical operators. Can you name all 3?
21. Slide
60 seconds
AND : If both expressions are true, then the whole condition is true. If one or both of the conditions are false, then the whole condition is false. OR : If one or both conditions are true, then the condition is true. It doesn’t matter whether the other condition is true or false. NOT : Switches the expression to its opposite (from true to false and false to true).
Python Logical Operators
22. Slide
60 seconds
Let’s say we want to display a special message when a player gets their experience points above 120 and is playing the game on hard mode. The compound conditional statement starts with an “if”. Then, we add a Boolean expression followed by the logical operator “AND” and the other Boolean expression.
Example
23. Slide
60 seconds
24. Slide
60 seconds