Quiz 00 Practice


Concepts on Quiz 0

Quiz 0 will cover the following concepts:

  • Syllabus and course policies - be familiar with them!
  • Lessons 0 through 7
  • Challenge Questions 0 through 2 including Environment Diagrams

Questions

The quiz itself will be similar in difficulty but longer in length than these practice questions. In addition to these questions, you should review all of your lesson responses on Gradescope. The kinds of questions you responded to on Gradescope will also be on the quiz.

Solutions for each problem can be found at the bottom of this page.

Memory Diagrams

  1. Produce a memory diagram for the following code snippet, being sure to include its stack and output.

  1. Produce a memory diagram for the following code snippet, being sure to include its stack and output.

Data Types

  1. str literals in Python can be surrounded in either single-quote characters or double-quote characters, though in COMP110 we prefer the latter. (T/F)
  2. TRUE and FALSE are valid bool values in Python. (T/F)
  3. An int literal can begin with a zero, but cannot end with a zero. (T/F)
  4. What function can we use to identify the type classification of any object in Python?
  5. What is the resulting data type of the following expression? int("20")

Expressions

  1. What is the evaluation of the following expression? type(9 / len( str(110))
  2. What is the result of the following expression? "440" + "20"
  3. What value of x would cause the following expression to evaluate to True? (3 + x) == (55 % 2 ** 4)
  4. What value does the following expression result in, and what is its type? 2 + 2 / 2 ** (2 * 0)
  5. Using subscription syntax and concatenation, write an expression that evaluates to "tar" using the following string: “the brown, lazy dog!".
  6. What data type do expressions with relational operators evaluate to?
  7. What does the following expression evaluate to? int("10" + "40") > 100 * 2

Conditionals

  1. Every if statement must have a paired else branch. (T/F)
  2. Lines contained in an else branch in Python do not have to be indented. (T/F)
  3. You can name a variable else in your program without Python confusing your variable’s name and the else keyword. (T/F)
  4. Given the following code snippet, what is the printed output with the specified values for x and y?

    18.1. When x = 3, y = 5?
    18.2. When x = 5, y = 3?
    18.3. When x = -5, y = 1?
    18.4. When x = 13, y = 8?
    18.5. When x = 4, y = 3?
  5. Every then or else block of an if-then statement is reachable by some value, regardless of the test conditions specified by the if statement.

Solutions

Memory Diagrams

Data Types

  1. T
  2. F
  3. F
  4. type()
  5. int

Expressions

  1. <class 'float'>
  2. “44020”
  3. 4
  4. 4.0
  5. “the brown, lazy dog!”[0] + “the brown, lazy dog!”[12] + “the brown, lazy dog!”[5]
  6. bool
  7. True

Conditionals

  1. False
  2. False
  3. False
  4. 18.1. 16.0
    18.2. 2.0
    18.3. -3.0
    18.4. 3.0
    18.5. 1
  5. False
Contributor(s): Megan Zhang, David Karash, Catherine Roberts