← Back to the Introduction to Computer Science outline The Course Maker
← Introduction to Computer Science outline
Week 8 · Midterm practice exam

Midterm Practice Exam

Introduction to Computer Science Free sample edition
The student view of the 25-question practice exam: fresh variants of the course's quiz items, never the scored exam's. The answer key and the feedback ship only inside the course's .imscc.
  1. An illustrative phone battery check uses an if, elif, else chain. Which message does it display?

    battery = 35
    full = 100
    if battery >= full:
        print("Fully charged")
    elif battery >= full // 4:
        print("Enough for today")
    else:
        print("Charge soon")

    Select one.

    • Enough for today
    • Fully charged
    • Charge soon
    • Enough for today, then Charge soon
  2. Select every range that produces exactly four numbers.

    Select every option that applies.

    • range(1, 4)
    • range(10, 14)
    • range(0, 9, 2)
    • range(4)
    • range(1, 12, 3)
  3. An illustrative step counter starts at 120 steps, aims for 1000, and adds 250 steps per walk. Which two values do the print lines show?

    target = 1000
    steps = 120
    walks = 0
    while steps < target:
        steps = steps + 250
        walks = walks + 1
    print(walks)
    print(steps)

    Select one.

    • 3, then 870
    • 4, then 1000
    • 5, then 1370
    • 4, then 1120
  4. Mark every line that this illustrative speed program prints.

    speed = 40
    
    def report():
        print("report reads", speed)
    
    def slow_down():
        speed = 15
        print("local", speed)
    
    report()
    slow_down()
    print("global", speed)

    Select every option that applies.

    • global 15
    • report reads 40
    • local 15
    • report reads 15
    • global 40
  5. Two names are set up in an illustrative bike-share program. Which of the following lines run without raising an error? Mark each one that does.

    city = "lakeside"
    riders = 32

    Select every option that applies.

    • print(city[8])
    • print(city[-8])
    • print("Riders: " + riders)
    • print(city[3:40])
    • print(riders[0])
  6. An illustrative coffee tracker builds its status line with an f-string. Which text does the second line display?

    cups = 3
    print(f"Brewed {cups} cups today")

    Select one.

    • Brewed {cups} cups today
    • Brewed cups cups today
    • TypeError
    • Brewed 3 cups today
  7. On the third pass of this illustrative loop over a word, which character does ch hold?

    for ch in "planet":
        print(ch)

    Select one.

    • a
    • n
    • l
    • p
  8. An illustrative seating chart uses a loop inside a loop. How many lines does it print?

    for row in range(4):
        for seat in range(2):
            print(row, seat)

    Select one.

    • 6
    • 8
    • 2
    • 4
  9. An illustrative temperature converter keeps only whole degrees by passing 7.6 to int. What appears on screen?

    print(int(7.6))

    Select one.

    • 7
    • 8
    • 7.6
    • 7.0
  10. An illustrative to-do app tries to add a whole number to a count stored as text. What is the result of running this line?

    print(4 + "2")

    Select one.

    • It prints 42
    • It prints 6
    • Nothing prints, and the last line names SyntaxError
    • Nothing prints, and the last line names TypeError
  11. In an illustrative receipt program, a 5-dollar delivery fee is added to 6 items that cost 7 dollars each. Predict, then run: which number does this line display?

    print(5 + 6 * 7)

    Select one.

    • 77
    • 18
    • 47
    • 210
  12. In this illustrative to-do program, line 2 is missing the quotation mark that should close its string. When you press Run, what shows up, and which exception type does the last error line name?

    print("To-do: wash dishes")
    print("Done: 2 of 5)

    Select one.

    • To-do: wash dishes appears, and then the last line names SyntaxError
    • To-do: wash dishes appears, and then the last line names NameError
    • Nothing appears, and the last line names SyntaxError
    • Both lines appear, and Python adds the missing quotation mark
  13. Predict, then run: which piece of the word LOOPING does this slice produce?

    print("LOOPING"[2:5])

    Select one.

    • OPI
    • OOP
    • OPIN
    • OOPI
  14. A chatbot claims that print("BINARY"[0:3]) displays BINA, because a slice keeps both of its end indexes. What is the best way to respond?

    Select one.

    • Accept BINA, because the chatbot named both of the indexes in its reply
    • Rephrase the question to the chatbot until it repeats the very same answer
    • Choose whichever chatbot reply sounds the most confident about the slice
    • Run the line in a Python runner and compare what it prints with the claim
  15. This illustrative loop was written to add 3, 4, 5, 6 and 7. Which total does it display?

    total = 0
    for n in range(3, 7):
        total += n
    print(total)

    Select one.

    • 25
    • 4
    • 18
    • 7
  16. An illustrative step counter reports its daily total with one print call that receives three values. Which output line appears?

    print("Steps:", 8000, "today")

    Select one.

    • Steps:8000today
    • Steps: 8000 today
    • Steps:, 8000, today
    • "Steps:" 8000 "today"
  17. An illustrative kitchen timer calls a function inside a for loop. How many lines does the program print altogether?

    def beep():
        print("Beep")
    
    print("Timer set")
    for i in range(3):
        beep()

    Select one.

    • 3
    • 5
    • 1
    • 4
  18. An illustrative password check compares a typed PIN. What happens when this program is run?

    pin = 4821
    if pin = 4821:
        print("Unlocked")

    Select one.

    • Unlocked appears once on the screen, with no error.
    • No output and no error message appear.
    • Unlocked appears, and then the error names NameError.
    • Nothing runs, and the error names SyntaxError.
  19. When a script has three print lines and no loops, branches or function calls, Python may run those lines in any order it chooses, so the output order can change from one run to the next.

    True or false.

    • True
    • False
  20. Work out a and not b on each row of a truth table, with the rows in the pinned order True True, True False, False True, False False. Which list gives its values in that order?

    Select one.

    • False, True, True, True
    • True, True, False, True
    • False, True, False, False
    • False, False, True, False
  21. An illustrative game raises its level by 2 each round. Which value is displayed once the loop has finished?

    level = 2
    while level <= 8:
        level = level + 2
    print(level)

    Select one.

    • 8
    • 12
    • 10
    • 6
  22. An illustrative bike-share label is sliced to pull out one word. Counting positions from 0, which text is displayed?

    label = "city bikeshare"
    print(label[5:9])

    Select one.

    • bike
    • ikes
    • bik
    • bikes
  23. An illustrative music app sets a volume, and a function assigns a new volume inside its own body. What is displayed?

    volume = 3
    
    def louder():
        volume = 11
    
    louder()
    print(volume)

    Select one.

    • 11
    • None
    • 3
    • NameError
  24. An illustrative temperature app stores a unit name and reads one character counted from the end. Which character appears?

    unit = "celsius"
    print(unit[-2])

    Select one.

    • s
    • i
    • u
    • IndexError
  25. An illustrative bike-share program spreads 12 bikes evenly across 4 racks. A first guess is that it shows 3. Which output does Python actually show?

    print(12 / 4)

    Select one.

    • 3
    • 48
    • 8
    • 3.0

Built with The Course Maker · samples.thecoursemaker.com