1/19
Comprehensive practice flashcards covering basic Python programming, data types, conditional branching, while and for loops, operator precedence, string operations, and list manipulation from CMPUT 101.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai | Chat |
|---|
No analytics yet
Send a link to your students to track their progress
According to CMPUT 101, how is Computing Science defined, and what is an algorithm?
Computing Science is the science of computation, which is the study of algorithms. An algorithm is defined as a step-by-step procedure for solving a problem or accomplishing a task.
What does the acronym IDLE stand for in Python, and what are its key features?
IDLE stands for Integrated Development and Learning Environment. Its primary features include syntax highlighting, code completion, an integrated debugger, detailed help documentation, and a shell window for immediate command execution.
What rules must be followed when naming variables in Python?
Variable names cannot contain spaces (they must be one unit, though underscores like _ are permitted), can include numbers but cannot begin with a number, and cannot use privileged language keywords such as print or input.
What error occurs when directly adding an integer and a string (e.g., 5 + "5"), and how can it be resolved?
Python raises a TypeError: unsupported operand type(s) for +: 'int' and 'str'. It is resolved by explicit type casting using int() (e.g., 5 + int("5")) for numeric addition or str() (e.g., str(5) + "5") for string concatenation.
How do Boolean values behave when evaluated in arithmetic operations with numeric operands?
Boolean values are treated as numeric: True has a value of 1 and False has a value of 0. Consequently, True - False evaluates to 1, and 4 - True evaluates to 3.
What occurs when a floating-point number is converted to an integer using int(), such as int(3.75)?
The decimal portion is truncated, converting 3.75 directly to 3.
In an if-elif-else control structure, how many code blocks are executed?
Only one code block will execute: the block belonging to the very first condition that evaluates to True. If none evaluate to True, the else block executes.

What control flow structure is represented by this flowchart?
A while loop: the condition diamond is evaluated first; if True, the loop code block executes and returns to test the condition again; if False, the loop exits.

What control flow structure is represented by this flowchart?
A for loop: it checks whether all items in a collection have been iterated over; if False, it assigns the next item to the loop variable and executes the loop code block; if True, the loop terminates.
What are the three parameters of Python's range() function, and what default values are used when parameters are omitted?
The syntax is range(start, stop, step), where start is inclusive, stop is exclusive, and step defines the increment size. If omitted, start defaults to 0 and step defaults to 1.
When is a for loop preferred over a while loop?
A for loop is typically used when iterating over a defined sequence or collection where the number of iterations is known in advance. A while loop is used when the exact number of iterations is unknown and code must repeat until a condition becomes false.
What keyboard shortcut is used to interrupt execution and break out of an infinite loop in Python?
The interrupt execution shortcut is Ctrl+C.
How does the associativity of the exponentiation operator (**) differ from other arithmetic operators under PEMDAS?
The exponentiation operator (**) is right-associative, evaluating from right to left (for example, 2 ** 3 ** 2 evaluates as 2(32)=29=512), whereas multiplication and division evaluate from left to right.
What is the final value of sum after executing:
sum = 0for i in range(3):for j in range(9, 1, -3):sum += j
The final sum is 54. For each of the 3 iterations of i (0,1,2), j iterates through values 9,6,3 adding 18 per outer loop cycle (3×18=54).

Based on zero-based indexing, what are the first index and the last index of the string "Hello World!"?
The first character ('H') has an index of 0, and the last character ('!') has an index of 11, which corresponds to len(string) - 1 or negative index −1.
Why does "hello" < "Hello" evaluate to False in Python?
String comparisons are case-sensitive and based on Unicode values, where uppercase letters have lower numerical values than lowercase letters; thus, "Hello" is strictly less than "hello".
How do Python lists and strings differ with respect to mutability, element types, and dynamic sizing?
Lists are mutable (elements can be modified, added, or removed in place), can store heterogeneous data types, and change length dynamically. Strings are immutable (characters cannot be reassigned directly), store only character sequences, and have fixed lengths.

How is the element 6 accessed from the nested list nested_list = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]?
It is accessed using double bracket notation: nested_list[1][2] (the element at index 2 of the sublist at index 1).
What is the difference in behavior between list.append(toadd) and list += toadd when list = [1, 2, 3, 4] and toadd = [5, 6]?
list.append(toadd) appends the collection itself as a single nested element resulting in [1, 2, 3, 4, [5, 6]], whereas list += toadd concatenates the individual elements to form [1, 2, 3, 4, 5, 6].
What do the slice operations my_list[2:3] and my_list[:4] return for my_list = ['a', 'b', 'c', 'd', 'e']?
my_list[2:3] returns ['c'] (extracting index 2 up to, but not including, index 3), and my_list[:4] returns ['a', 'b', 'c', 'd'] (extracting from the beginning up to, but not including, index 4).