← Back to the Introduction to Computer Science outline The Course Maker
← Introduction to Computer Science outline
Week 7 · Quiz

Week 7 Quiz

Introduction to Computer Science Free sample edition
The student view of the 10-question quiz: each question and its options as they appear in Canvas. The answer key and the feedback ship only inside the course's .imscc (Classic QTI); they are not shown on this public page.
  1. Predict, then check: which line does this program print first?

    def greet():
        print("Hello from inside the function")
    
    print("Defined, not yet called")
    greet()
    greet()

    Select one.

    • Hello from inside the function
    • Defined, not yet called
    • Nothing; the def block raises an error first
    • Hello from inside the function, printed by the def line
  2. Predict, then check: what does this program print?

    def pages_left(goal, pages_read):
        return goal - pages_read
    
    print(pages_left(300, 45))

    Select one.

    • 345
    • −255
    • 255
    • 45
  3. Predict, then check: the arguments are written in a different order. What does this program print?

    def pages_left(goal, pages_read):
        return goal - pages_read
    
    print(pages_left(45, 300))

    Select one.

    • −255
    • 255
    • 0
    • TypeError
  4. Predict, then check: what does this program print?

    def pages_left(goal, pages_read):
        return goal - pages_read
    
    print(pages_left(200, 45) // 30)

    Select one.

    • 155
    • 6
    • 8
    • 5
  5. Predict, then check: what does this program print?

    def show(x):
        print(x * 2)
    
    print(show(4))

    Select one.

    • 8, then None on a second line
    • 8 only
    • None only
    • 8, then 8 again on a second line
  6. Predict, then check: what does this program print?

    n = 5
    
    def change():
        n = 99
    
    change()
    print(n)

    Select one.

    • 99
    • 5
    • None
    • NameError
  7. This program prints 8 and then stops with an error. Reading the error from the bottom up, which exception type does its last line name?

    def double(x):
        print(x * 2)
    
    y = double(4)
    print(y + 1)

    Select one.

    • NameError
    • SyntaxError
    • TypeError
    • ValueError
  8. Predict, then check: how many lines does this program print in all?

    def greet():
        print("Hello from inside the function")
    
    print("Defined, not yet called")
    for i in range(2):
        greet()

    Select one.

    • 2
    • 4
    • 1
    • 3
  9. Select every line this program prints.

    level = 100
    
    def show():
        print("inside sees", level)
    
    def reset():
        level = 0
        print("inside", level)
    
    show()
    reset()
    print("outside", level)

    Select every option that applies.

    • inside sees 100
    • outside 0
    • inside 0
    • outside 100
    • inside sees 0
  10. A chatbot claims this program prints a single line, 8, because show returns the value it prints. True or false: running the program confirms the chatbot's claim.

    def show(x):
        print(x * 2)
    
    print(show(4))

    True or false.

    • True
    • False

Built with The Course Maker · samples.thecoursemaker.com