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

Week 12 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: this program saves the reading log and reads it back. What does it print?

    daily = [12, 40, 25]
    with open("reading_log.txt", "w") as f:
        for pages in daily:
            f.write(str(pages) + "\n")
    
    total = 0
    with open("reading_log.txt") as f:
        for line in f:
            total = total + int(line.strip())
    print(total)

    Select one.

    • 77
    • 124025
    • TypeError
    • 0
  2. Predict, then check: what does this program print, or which exception type ends it?

    daily = [12, 40, 25]
    with open("reading_log.txt", "w") as f:
        for pages in daily:
            f.write(str(pages) + "\n")
    
    total = 0
    with open("reading_log.txt") as f:
        for line in f:
            total = total + line
    print(total)

    Select one.

    • 77
    • ValueError
    • TypeError
    • NameError
  3. Predict, then check: what does the last line of this program print?

    with open("tasks.txt", "w") as f:
        f.write("email\n")
        f.write("lunch\n")
    
    with open("tasks.txt", "w") as f:
        f.write("gym\n")
    
    with open("tasks.txt") as f:
        print(f.read().split())

    Select one.

    • ['email', 'lunch', 'gym']
    • ['email', 'lunch']
    • []
    • ['gym']
  4. Predict, then check: what does the last line of this program print?

    daily = [12, 40, 25]
    with open("reading_log.txt", "w") as f:
        for pages in daily:
            f.write(str(pages) + "\n")
    
    with open("reading_log.txt") as f:
        lines = f.readlines()
    print(len(lines[0]))

    Select one.

    • 2
    • 3
    • 1
    • 12
  5. Select every line this program prints.

    try:
        n = int("42")
        print("ok", n + 1)
    except ValueError:
        print("not a number")
    
    try:
        n = int("forty-two")
        print("ok", n + 1)
    except ValueError:
        print("not a number")
    
    try:
        with open("no_such_file.txt") as f:
            print(f.read())
    except FileNotFoundError:
        print("no file yet")

    Select every option that applies.

    • ok 43
    • not a number
    • no file yet
    • ok 42
    • FileNotFoundError
  6. Predict, then check: what is the second line this program prints?

    try:
        print("before")
        print(10 / 0)
        print("after")
    except ZeroDivisionError:
        print("cannot divide by zero")
    print("still running")

    Select one.

    • after
    • still running
    • ZeroDivisionError
    • cannot divide by zero
  7. Predict, then check: what does this program print, or which exception type ends it?

    try:
        print(int("3.5"))
    except ZeroDivisionError:
        print("caught it")

    Select one.

    • ValueError
    • caught it
    • 3
    • ZeroDivisionError
  8. Read the last line of the traceback: which exception type ends this program?

    print(int("3.5"))

    Select one.

    • TypeError
    • ValueError
    • NameError
    • SyntaxError
  9. True or false: the program pages = 0, then print("before"), then print(10 / pages), then print("after") prints before and then stops with ZeroDivisionError, so the line that would print after never runs.

    True or false.

    • True
    • False
  10. Predict, then check: what does this program print, or which exception type ends it?

    daily = [12, 40, 25]
    try:
        total = 0
        for pages in daily:
            total = total + pages
        print(totl)
    except:
        print("could not add the log")

    Select one.

    • 77
    • Nothing prints
    • could not add the log
    • NameError

Built with The Course Maker · samples.thecoursemaker.com