Docsity

PCEP-30-02 Module 3 Study Guide Boolean Values, Conditional Execution, Loops & Logic 2026-, Exams of Advanced Education

Toggle sidebar
bg1
PCEP-30-02 Module 3 Study Guide | Boolean Values,
Conditional Execution, Loops & Logic 2026
if-elif-else statement - correct answer ✔✔cascade- way of assembling the
statetment.
if the_weather_is_good:
go_for_a_walk()
elif tickets_are_available:
go_to_the_theater()
elif table_is_available:
go_for_lunch()
else:
play_chess_at_home()
range() function - correct answer ✔✔generates a sequence of numbers. It
accepts integers and returns range objects.
The syntax of range() looks as follows: range(start, stop, step),
where:
**start is an optional parameter specifying the starting number of the
sequence (0 by default)
**stop is an optional parameter specifying the end of the sequence
generated (it is not included),
**step is an optional parameter specifying the difference between the
numbers in the sequence (1 by default.)
pf3
pf4
pf5
pf8

Partial preview of the text

Download PCEP-30-02 Module 3 Study Guide Boolean Values, Conditional Execution, Loops & Logic 2026- and more Exams Advanced Education in PDF only on Docsity!

PCEP-30-02 Module 3 Study Guide | Boolean Values,

Conditional Execution, Loops & Logic 2026

if-elif-else statement - correct answer ✔✔cascade- way of assembling the statetment. if the_weather_is_good: go_for_a_walk() elif tickets_are_available: go_to_the_theater() elif table_is_available: go_for_lunch() else: play_chess_at_home() range() function - correct answer ✔✔generates a sequence of numbers. It accepts integers and returns range objects. The syntax of range() looks as follows: range(start, stop, step), where: **start is an optional parameter specifying the starting number of the sequence (0 by default) **stop is an optional parameter specifying the end of the sequence generated (it is not included), **step is an optional parameter specifying the difference between the numbers in the sequence (1 by default.)

ex: for i in range(3): print(i, end=" ") # Outputs: 0 1 2 for i in range(6, 1, -2): print(i, end=" ") # Outputs: 6, 4, 2 bitwise operators - correct answer ✔✔&, |, ^, ~, <<, >> ***allow you to manipulate single bits of data. & (ampersand) - bitwise conjunction; | (bar) - bitwise disjunction; ~ (tilde) - bitwise negation; ^ (caret) - bitwise exclusive or (xor). & requires exactly two 1s to provide 1 as the result; | requires at least one 1 to provide 1 as the result; ^ requires exactly one 1 to provide 1 as the result. Bitwise Right Shift Operator: >>

list comprehension example - correct answer ✔✔the code creates a five- element list filled with with the first five natural numbers raised to the power of 3: cubed = [num ** 3 for num in range(5)] print(cubed) # outputs: [0, 1, 8, 27, 64] nested list - correct answer ✔✔A list that is itself contained within a list.

  • use nested lists in Python to create matrices (i.e., two-dimensional lists). like a four column/four-row table -which would be a two dimensional array (4*4) ex of a nested list - correct answer ✔✔-this is ex of a 2 dimensional array board = [] for i in range(8): row = [EMPTY for i in range(8)] board.append(row) ***the inner part of the loop creates a row consisting of eight elements (each of them equal to EMPTY) and appends it to the board list; ****the outer part repeats it eight times; in total, the board list consists of 64 elements (all equal to EMPTY)

The board variable is now a two-dimensional array. It's also called, by analogy to algebraic terms, a matrix. Nested List Comprehension - correct answer ✔✔board = [[EMPTY for i in range(8)] for j in range(8)] The inner part creates a row, and the outer part builds a list of rows. while loop - correct answer ✔✔a programming construct used to repeat a set of commands (loop) as long as (while) a boolean condition is true while True: '''Code to be repeated''' if loop condition stays True forever, it is called an infinite loop because it will not stop looping. this may cause an error, prg. will crash* nested list ex - correct answer ✔✔t =[[3-i for i in range(3)] for j in range(3)] s = 0 for i in range(3): s+= t[i][i] print(s) t = [[3,2,1],[3,2,1],[3,2,1]] s = 6 because it is included in a for loop which will repeat the condition s += t[i][i] 3 times. s = t[0][0], t[1][1], t[2][2]

method - correct answer ✔✔specific kind of function - it behaves like a function and looks like a function, but differs in the way in which it acts, and in its invocation style. is also able to change the state of a selected entity. A method is owned by the data it works for, while a function is owned by the whole code. A typical method invocation usually looks like this: result = data.method(arg) ***the name of the method is preceded by the name of the data which owns the method. Next, you add a dot, followed by the method name, and a pair of parenthesis enclosing the arguments.

  • add new elements to an existing list done with methods owned by all the lists, not by functions. function - correct answer ✔✔doesn't belong to any data - it gets data, it may create new data and it (generally) produces a result. A method is owned by the data it works for, while a function is owned by the whole code. a typical function invocation may look like this: result = function(arg)

The function takes an argument, does something, and returns a result. .append() method - correct answer ✔✔adds element to an existing list: list.append(value) it takes its argument's value and puts it at the end of the list which owns the method. The list's length then increases by one. .insert() method - correct answer ✔✔it can add a new element at any place in the list, not only at the end. list.insert(location, value) It takes two arguments: ***the first shows the required location of the element to be inserted; note: all the existing elements that occupy locations to the right of the new element (including the one at the indicated position) are shifted to the right, in order to make space for the new element; ***the second is the element to be inserted. numbers.insert(0, 222) print(numbers) [222, 111, 7, 2, 1, 4]