franklopez1989
franklopez1989 Jan 23, 2026 • 0 views

Input/Output in Python Quiz for AP Computer Science Principles

Hey AP Computer Science Principles friends! 👋 Getting tripped up by Input/Output in Python? No worries, I've got you covered! Check out this quick study guide and then test your skills with the practice quiz. You got this! 💪
💻 Computer Science & Technology

1 Answers

✅ Best Answer
User Avatar
coffey.joanna65 Jan 1, 2026

📚 Quick Study Guide

  • ⌨️ Input allows a program to receive data from the outside world (e.g., user). The `input()` function reads a line from input, converts it to a string, and returns it.
  • 📤 Output allows a program to display data to the user. The `print()` function displays values to the console.
  • ➡️ Implicit Type Conversion: Be aware that `input()` returns a string. You may need to convert this string to an integer or float using `int()` or `float()` if you intend to perform numerical operations. For example: `age = int(input("Enter your age: "))`
  • 🔢 Formatting Output: Use f-strings or the `.format()` method to create formatted output strings. Example with f-strings: `name = "Alice"; print(f"Hello, {name}!")`
  • 🗄️ File I/O: Python can read from and write to files. Use the `open()` function with modes like `'r'` (read), `'w'` (write), and `'a'` (append). Remember to `close()` the file after use or use a `with` statement.
  • ⚠️ Error Handling: When dealing with user input, anticipate potential errors, like users entering non-numeric data when a number is expected. Use `try...except` blocks to handle these exceptions gracefully.

🧪 Practice Quiz

  1. What function is used to get input from the user in Python?
    1. print()
    2. output()
    3. input()
    4. read()
  2. What data type does the `input()` function return?
    1. Integer
    2. Float
    3. String
    4. Boolean
  3. How would you convert the user's input to an integer?
    1. str(input())
    2. float(input())
    3. int(input())
    4. input().int()
  4. Which of the following modes is used to open a file for writing?
    1. 'r'
    2. 'a'
    3. 'w'
    4. 'x'
  5. What is the purpose of the `try...except` block?
    1. To define a function
    2. To handle errors
    3. To loop through a list
    4. To declare a variable
  6. How would you format the output to display "The price is $10.00" if the variable `price = 10`?
    1. print("The price is $" + price)
    2. print(f"The price is ${price}")
    3. print("The price is $", price)
    4. print("The price is $%.2f" % price)
  7. What does the `'a'` mode do when opening a file?
    1. Opens the file for reading.
    2. Opens the file for writing, overwriting the file if it exists.
    3. Opens the file for appending, creating the file if it doesn't exist.
    4. Opens the file for exclusive creation, failing if the file exists.
Click to see Answers
  1. C
  2. C
  3. C
  4. C
  5. B
  6. B
  7. C

Join the discussion

Please log in to post your answer.

Log In

Earn 2 Points for answering. If your answer is selected as the best, you'll get +20 Points! 🚀