IT101-1L midterms lesson 8-12 Flashcards
allow you to make decisions and execute different code blocks based on certain conditions.
selection structures
allows you to execute a block of code only if a specified condition is True.
if statement
extends the if statement by providing an alternative code block to be executed when the condition is False
if-else statement
t allows you to evaluate multiple conditions in a sequential manner. It is used when you have more than two possible outcomes
if-elif-else statement
are used in programming to compare values and determine the relationship between them.
Relational operators
is used within loops (such as for or while) to exit the loop immediately.
break statement
Checks if two values are equal.
== (equal to):
Checks if two values are not equal.
!= (not equal to):
> (greater than): Checks if the left operand is greater than the right operand.
> (greater than):
Checks if the left operand is less than the right operand.
< (less than):
Checks if the left operand is greater than or equal to the right operand.
> = (greater than or equal to):
Checks if the left operand is less than or equal to the right operand.
<= (less than or equal to):
The and operator returns True if both of its operands are True, and False otherwise.
and:
The or operator returns True if at least one of its operands is True, and False otherwise.
or:
: The not operator reverses the logical state of its operand. If the operand is True, the not operator returns False, and if the operand is False, it returns True.
not
means that the second operand of an and or or operator is not evaluated if the outcome can be determined solely by evaluating the first operand.
Short-circuit evaluation
you can control the flow of your program and stop the loop execution based on certain conditions.
break statement,
is an expression that evaluates to either True or False.
condition
The _________ statement can be extended to include multiple conditions using the _____
if…else, elif
By using _________, you can create decision trees with multiple branches, allowing your program to respond differently based on different conditions.
multiple elif clauses
refer to the practice of placing one or more if…else statements inside another if or else block.
Nested decisions
, are fundamental programming constructs that allow you to repeat a code block multiple times based on specified conditions.
Iterative structures, commonly known as loops
evaluates the condition before executing the code block.
The while loop
in Python is used to iterate over elements of an iterable
The for loop
They allow you to repeat code blocks based on conditions, which helps automate repetitive tasks and control program flow
Loops (Iterative structures)
is a fundamental iterative structure in Python programming that allows you to repeat a code block as long as a specified condition is true.
while loop
is a powerful iterative structure in Python that allows you to repeat a code block a specific number of times or iterate over elements in a sequence
for loop
provide a powerful way to perform repetitive tasks that require multiple iterations.
Nested loops
Nested loops are essential in programming as they allow you to work with complex data structures and perform operations on multiple dimensions
Nested loops
is used to prematurely terminate the execution of a loop
break statement
statement is used to skip the current iteration of a loop and move to the next iteration.
continue
is used within loops (such as for or while) to skip the remaining statements within the loop’s code block and move to the next iteration
The continue statement
is a versatile and fundamental data structure that allows you to store a collection of elements of different types.
list
provide a convenient way to organize and manipulate data as a sequence of items.
Lists
: Lists allow you to group related data elements of various types into a single entity.
Grouping related data
To create a list in Python, you can simply use
square brackets []
returns the number of elements present in a list
len() function
allows you to add an element to the end of the list. It modifies the original list in place.
append() function