Quiz 00 Practice


Questions

The quiz itself will be similar in difficulty to 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. (But if you’re unsure, before looking up the solution, try figuring it out on your own or testing it out in Visual Studio!)

Data Types

  1. str literals in Python can be surrounded in either single-quote characters ('like this') or double-quote characters ("like this"), though in COMP110 we prefer the double-quotes. (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?

Solutions

Expressions

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

Solutions

Conditionals

  1. Every if statement must be followed by 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. (If you are unsure, this is a good one to try yourself!) (T/F)

  4. All subquestions of this problem will refer to this code snippet:

     x: int = int(input("Pick a number: "))
     y: int = 10
     z: int = 2
     x = x - 1
     if x < 10:
         print("A")
     else:
         if (x % z) == 0:
             print ("B")
     if x == (y + z):
         print("C")
     else: 
         print("D")

For the following subquestions, answer with a valid input value for x that would cause the given letter to print. It is OK for your input to cause other letters to print as well. If there is no such value, write “Unreachable”.

4.1 A

4.2 B

4.3 C

4.4 D

Now, answer with a valid input value for x that would cause the exact given letter(s) to print (no other letters). If there is no such value, write “Unreachable”.
4.5

A
C

4.6

B
C

4.7

C

4.8

D

Solutions

Boolean Operators

  1. What is the result of the following boolean expressions?
    5.1. ((not False) and True) == True
    5.2. (not False) or (True and False)
    5.3. True and (7 < 3 * 4 / 6)
    5.4. (not False) != True
    5.5. not(True and False) and (False or not False)

Solutions

Memory Diagrams

You can find practice memory diagrams on the Practice Memory Diagrams Page. For this quiz, you should know how to do the ones under “Basics” and “Conditionals”.

More Practice

Check out the weekly tutoring problems for more practice, and be sure to attend tutoring!

Solutions

Data Types Solutions

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

Expressions Solutions

  1. 20, int

  2. "20232023", str

  3. <class 'float'> (Or just float is sufficient on a quiz.)

  4. "44020"

  5. 4

  6. 4.0

  7. There are two possible answers:

    "Saturday"[2] + "Saturday"[1] + "Saturday"[4]

    or

    "Saturday"[2] + "Saturday"[6] + "Saturday"[4]

  8. bool

  9. True

Conditionals Solutions

  1. F

  2. F

  3. F

  4. 4.1 Any value < 11

    4.2 Any value >= 11 and odd. (Since x % z == 0 must be True and z is 2, this means x - 1 must be even.)

    4.3 13

    4.4 Any value != 13

    4.5 Unreachable

    4.6 13

    4.7 Unreachable

    4.8 Any value >= 11 and even

Boolean Operators Solutions

  1. 5.1. True
    5.2. True
    5.3. False
    5.4. False
    5.5. True
Contributor(s): Megan Zhang, David Karash, Alyssa Lytle