CMPUT 101: Introduction to Python Programming, Data Types, Control Structures, and Collections

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/19

flashcard set

Earn XP

Description and Tags

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.

Last updated 2:47 AM on 10/12/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

20 Terms

1
New cards

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.

2
New cards

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.

3
New cards

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.

4
New cards

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.

5
New cards

How do Boolean values behave when evaluated in arithmetic operations with numeric operands?

Boolean values are treated as numeric: True has a value of 11 and False has a value of 00. Consequently, True - False evaluates to 11, and 4 - True evaluates to 33.

6
New cards

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 33.

7
New cards

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.

8
New cards
<p>What control flow structure is represented by this flowchart?</p>

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.

9
New cards
<p>What control flow structure is represented by this flowchart?</p>

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.

10
New cards

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 00 and step defaults to 11.

11
New cards

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.

12
New cards

What keyboard shortcut is used to interrupt execution and break out of an infinite loop in Python?

The interrupt execution shortcut is Ctrl+C.

13
New cards

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=5122^{(3^2)} = 2^9 = 512), whereas multiplication and division evaluate from left to right.

14
New cards

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 5454. For each of the 33 iterations of i (0,1,20, 1, 2), j iterates through values 9,6,39, 6, 3 adding 1818 per outer loop cycle (3×18=543 \times 18 = 54).

15
New cards
<p>Based on zero-based indexing, what are the first index and the last index of the string <code>"Hello World!"</code>?</p>

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 00, and the last character ('!') has an index of 1111, which corresponds to len(string) - 1 or negative index −1-1.

16
New cards

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".

17
New cards

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.

<p>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.</p>
18
New cards

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 22 of the sublist at index 11).

19
New cards

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].

20
New cards

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 22 up to, but not including, index 33), and my_list[:4] returns ['a', 'b', 'c', 'd'] (extracting from the beginning up to, but not including, index 44).