Lecture 2 – Program Flow, Conditionals, Loops

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

1/21

flashcard set

Earn XP

Description and Tags

Flashcards covering key concepts from Lecture 2 of Programming Essentials: variables, naming conventions, built-in functions, operators, PEMDAS, string operations, loops, conditionals, Boolean algebra, and De Morgan's laws.

Last updated 1:20 PM on 10/15/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

22 Terms

1
New cards

What are the five stages of problem solving identified in the lecture?

  1. Problem formulation (input / output)
  2. Formalism (math?)
  3. Algorithm (steps)
  4. Implementation (engineering)
  5. Testing (are we good?)
2
New cards

What is the difference between == and ==== in Python?

== is the assignment token used to assign a value to a variable, whereas ==== is the comparison operator used to test equality.

3
New cards

What are three conditions that make a variable name illegal in Python?

  1. Beginning with a number (e.g., 76trombones76\text{trombones})
  2. Containing an illegal character (e.g., \text{more}\)
  3. Using a reserved keyword (e.g., class\text{class})
4
New cards

What formatting tools are recommended to improve code readability alongside meaningful variable names?

Comments (#\#) and blank lines.

5
New cards

What quoting styles can be used to enclose strings in Python?

Single quotes (′′''), double quotes (""""), or three of each (′′′′′′'''''' or """""""""""").

6
New cards

What is the difference between standard division (//) and floor division (////) in Python?

Standard division (//) yields a floating-point result, whereas floor division (////) divides and rounds down to the nearest integer.

7
New cards

In Python PEMDAS evaluation order, what is unique about the exponentiation operator (∗∗**)?

While operators at the same precedence level evaluate left-to-right, exponentiation (∗∗**) evaluates right-to-left (for example, 2∗∗3∗∗2=2∗∗9=5122 ** 3 ** 2 = 2 ** 9 = 512).

8
New cards

What is the modulus operator (%\%) and what is its precedence level?

It calculates the remainder when the first integer operand is divided by the second, and it shares the same precedence as multiplication and division.

9
New cards

How does the built-in function int()\text{int}() behave when passed a float such as 3.99993.9999 or −3.999-3.999?

It discards the fraction and truncates toward zero without rounding to the closest integer, returning 33 and −3-3 respectively.

10
New cards

How do the ++ and ∗* operators behave when applied to strings in Python?

++ performs string concatenation, while ∗* performs string repetition (requiring one string operand and one integer operand).

11
New cards

What data type is returned by Python's built-in input()\text{input}() function?

It always returns a string (str\text{str}).

12
New cards

What is composition in programming?

The combination of small building blocks—such as variables, expressions, statements, and function calls—into larger program chunks.

13
New cards

In a Python for\text{for} loop, how is the loop body defined?

The loop body is defined by indentation, which determines exactly which statements are executed within the body.

14
New cards
<p>What programming process does this flowchart depict?</p>

What programming process does this flowchart depict?

The control flow of a for\text{for} loop iterating over a sequence.

15
New cards
<p>Which conditional construct is illustrated by this flowchart?</p>

Which conditional construct is illustrated by this flowchart?

An if−else\text{if}-\text{else} conditional statement branching between two separate statement blocks.

16
New cards
<p>Which conditional construct is depicted in this flowchart?</p>

Which conditional construct is depicted in this flowchart?

Chained conditionals (if−elif−else\text{if}-\text{elif}-\text{else}).

17
New cards

When is the else\text{else} clause of a for−else\text{for}-\text{else} loop executed?

It executes when the loop completes all iterations without encountering an early break\text{break}.

18
New cards

After whom are Boolean values named?

British mathematician George Boole, who first formulated Boolean algebra.

19
New cards

How does short-circuit evaluation operate for Python's or\text{or} and and\text{and} logical operators?

For or\text{or}, if the left expression is True\text{True}, Python does not evaluate the right operand. For and\text{and}, if the left expression is False\text{False}, Python does not evaluate the right operand.

20
New cards

What are the logical opposites of the comparison operators ====, !=$, <,,

  • ==== is opposite to !=$\n- !=isoppositetois opposite to==\n- <isoppositetois opposite to>=$
  • <=<= is opposite to >$\n- >isoppositetois opposite to<=$
  • >=>= is opposite to <<
21
New cards

What are De Morgan's Laws expressed in Python syntax?

  1. not (x and y)==(not x) or (not y)\text{not } (x \text{ and } y) == (\text{not } x) \text{ or } (\text{not } y)
  2. not (x or y)==(not x) and (not y)\text{not } (x \text{ or } y) == (\text{not } x) \text{ and } (\text{not } y)
22
New cards

Using De Morgan's laws and logical opposites, how can if not ((sword_charge>=0.90) and (shield_energy>=100)):\text{if not } ((\text{sword\_charge} >= 0.90) \text{ and } (\text{shield\_energy} >= 100)): be simplified?

if (sword_charge<0.90) or (shield_energy<100):\text{if } (\text{sword\_charge} < 0.90) \text{ or } (\text{shield\_energy} < 100):