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

Week 3 — Quiz (auto-graded) · Input / Output & Strings

Introduction to Computer Science · CSCI 1101 Fall 2026 · Prof. Okafor Fictional sample

Course: Introduction to Computer Science — CS1 / Programming Fundamentals in Python (CSCI 1101) · Silver Oak University (fictional sample) · Prof. Okafor
Objective tested: Objective 2 — input/output and strings: input() (always a string), f-strings, indexing & slicing, len(), and the IndexError.
Points: 10 (1 each) · Assignment group: Quizzes (10% of grade) · Due: end of Module 3.

This is the human-readable quiz with its vetted answer key and feedback. The import-ready Classic QTI is in F-quiz-week-03-qti.xml (generated by the shared validated script — parses with 10 items, every single-answer item exactly one correct). Execution gate: PASS — every "what does this print?" key below was produced by actually running the code in Python, not hand-traced. The Canvas placement block is at the bottom of this file.


Blueprint

# Type Concept Objective
1 Multiple choice input() always returns a string (concept) 2
2 Multiple choice Predict the output — f-string + slicing (s[:3]) 2
3 Multiple choice Predict the output — slice with exclusive stop (s[1:4]) 2
4 Multiple choice Predict the output — negative index (s[-1]) 2
5 Multiple answer True statements about input(), slicing, len, f-strings 2
6 Matching Slice/index expression → result (for s = "PYTHON") 2
7 Multiple choice Predict the outputlen() 2
8 True / False "A slice s[1:4] includes index 4" misconception 2
9 Multiple choice Debuggingprint(s[6]) raises an IndexError 2
10 Multiple choice Debugging — adding 1 to input() raises a TypeError; the int() fix 2

No trick questions; distractors are plausible mis-traces (including the exclusive stop, off-by-one indexing, string-vs-number confusion, wrong error type).


Questions, key, and feedback

Q1 (MC). A program runs x = input("Type a number: ") and the user types 5. What is the type of the value stored in x?
- A. int, because the user typed a number
- B. strinput() always returns a string
- C. float, because all input is decimal
- D. it depends on what the user types
Feedback: input() always returns a str — even when the user types digits, x holds the string '5', not the number 5. If you need to do math, convert it: int(input(...)). (Run-verified: type(x) is <class 'str'>.)

Q2 (MC). What does this program print?

s = "PYTHON"
print(s[:3])
  • A. PYTH
  • B. PYT
  • C. YTH
  • D. PYTHON
    Feedback: When the start is omitted it defaults to 0, and the stop 3 is excluded, so s[:3] takes positions 0, 1, 2 → PYT. (Run-verified: PYT.)

Q3 (MC). What does this program print?

s = "PYTHON"
print(s[1:4])
  • A. YTHO
  • B. YTH
  • C. YT
  • D. PYTH
    Feedback: A slice s[start:stop] includes start but excludes stop, so s[1:4] is positions 1, 2, 3 → YTH (the O at index 4 is left out). This exclusive stop is the #1 slicing trap. (Run-verified: YTH. YTHO wrongly includes index 4.)

Q4 (MC). What does this program print?

s = "PYTHON"
print(s[-1])
  • A. P
  • B. O
  • C. N
  • D. an error
    Feedback: A negative index counts from the right: -1 is the last character, which is N. (-2 would be O. Run-verified: N.)

Q5 (Multiple answer — select all that apply). Which of the following statements are true?
- A. input() always returns a string
- B. In a slice s[1:4], index 4 is not included
- C. len("cat") is 2
- D. An f-string like f"Hi {name}" replaces {name} with the value of name
- E. s[len(s)] returns the last character of s
Feedback: input() returns a string (A), a slice's stop is exclusive (B), and an f-string substitutes the variable's value (D). C is falselen("cat") is 3. E is falses[len(s)] is one past the end and raises an IndexError; the last character is s[-1] (or s[len(s) - 1]).

Q6 (Matching). For s = "PYTHON", match each expression to what it prints.
| Expression | Correct result |
|---|---|
| s[0] | P |
| s[-1] | N |
| s[1:3] | YT |
| s[:2] | PY |
Feedback: s[0] is the first character P; s[-1] is the last character N; s[1:3] is positions 1–2 (stop 3 excluded) → YT; s[:2] is positions 0–1 (stop 2 excluded) → PY. (All run-verified on s = "PYTHON".)

Q7 (MC). What does this program print?

word = "hello"
print(len(word))
  • A. 4
  • B. 5
  • C. 6
  • D. hello
    Feedback: len(word) counts the characters in the string: h-e-l-l-o is 5. (Run-verified: 5. Note the valid indices are then 0 through 4.)

Q8 (True / False). "For any string s, the slice s[1:4] includes the character at index 4."
- True
- False
Feedback: False. A slice's stop is exclusives[1:4] includes indices 1, 2, and 3 but not 4. (For "PYTHON", s[1:4] is YTH, not YTHO.)

Q9 (MC). This program crashes:

s = "sun"
print(s[7])

What error does Python report, and why?
- A. a SyntaxError, because [7] is invalid syntax
- B. no error; it prints an empty line
- C. an IndexError, because "sun" has no index 7 (valid indices are 0–2)
- D. a TypeError, because you can't index a string
Feedback: "sun" has length 3, so its valid indices are 0, 1, 2. Asking for index 7 is past the end, so Python raises IndexError: string index out of range. The last character is s[2] or s[-1]. (Run-verified: IndexError. Strings can be indexed, so D is wrong.)

Q10 (MC). This program is supposed to add 1 to a number the user types, but it crashes:

n = input("n: ")
print(n + 10)

What is wrong, and how do you fix it?
- A. Nothing is wrong; it prints the number plus 10
- B. print can't take a number; remove the + 10
- C. n is a string (input() returns a string); fix it with n = int(input("n: "))
- D. You must put quotes around 10
Feedback: input() returns a string, so n is text and n + 10 tries to add a number to text → TypeError: can only concatenate str (not "int") to str. The fix is to convert the input: n = int(input("n: ")), then n + 10 does real math. (Putting quotes around 10 (D) would just join two strings, not add. Run-verified: the original raises a TypeError.)


Answer key (quick reference)

Q Answer
1 B (str)
2 B (PYT)
3 B (YTH)
4 C (N)
5 A, B, D
6 s[0]→P / s[-1]→N / s[1:3]→YT / s[:2]→PY
7 B (5)
8 False
9 C (IndexError)
10 C (int(input(...)))

Quality gate (self-checked): each single-answer item has exactly one correct option; the multiple-answer item keys A, B, D (and requires C and E unselected); the matching item pairs four expressions to four distinct results. Execution gate: PASS — the keys for the predict-the-output items (Q2 PYT; Q3 YTH; Q4 N; Q6 all four; Q7 5) and the error items (Q9 IndexError; Q10 TypeErrorint() fix) were each produced by running the code in Python, not hand-traced. Distractors are plausible mis-traces (Q3 YTHO = including the exclusive stop; Q2 PYTH = off-by-one; Q5 E = s[len(s)] over-index).


Item-bank entries (for variants + the midterm/final)

All ten items are tagged course=CSCI1101 · week=3 · objective=2 · topic=io-and-strings and deposited in Item Bank: Week 3 — Input/Output & Strings. The midterm (Week 8) and the per-term variant updates draw fresh items from this bank. (Tags: q1 input-returns-str, q2 slice-default-start, q3 slice-exclusive-stop, q4 negative-index, q5 true-statements, q6 slice-match, q7 len, q8 exclusive-stop-tf, q9 indexerror, q10 input-typeerror-fix.)

Canvas placement block

canvas_object   = Quizzes::Quiz
title           = "Week 3 Quiz — Input/Output & Strings"
assignment_group = "Quizzes"
points_possible = 10
grading_type    = points
due_offset_days = 6        # 6 days after module start
published       = true
shuffle_answers = true
ai_permitted    = false    # AI is not permitted on quizzes
provenance      = "~ Prof. Okafor's edition · Fall 2026 · built with thecoursemaker.com"
This is the human-readable quiz with its vetted answer key and rationale. The import-ready Classic-QTI version (F-quiz-week-03-qti.xml) ships inside the course's .imscc package — it lands in the Canvas gradebook on import.

~ Prof. Okafor's edition · Fall 2026 · built with thecoursemaker.com