PYnative

Python Programming

  • Learn Python
    • Python Tutorials
    • Python Basics
    • Python Interview Q&As
  • Exercises
  • Quizzes
  • Code Editor
Home » Python » Quizzes » Python Input and Output Quiz

Python Input and Output Quiz

Updated on: August 26, 2025 | 7 Comments

This Python Input and Output Quiz provides Multiple Choice Questions (MCQs) to help you get familiar with the built-in print() and input() functions for performing input and output tasks in Python. Additionally, we will practice file handling in Python.

Also, See:

  • Python Input and Output Exercise
  • 15 Python Quizzes: each focusing on a specific topic
  • The quiz contains 25 questions. There is no time limit.
  • You will get 1 point for each correct answer. Solve 15 correctly to pass the test.

Read the below tutorials to solve this quiz.

  • Python Input and Output
  • Python File Handling

1. Which method is used to read all lines from a file into a list of strings, where each string represents a line?

 
 
 
 

2. What is true for file mode 'x'

Hint: Create File in Python

 
 
 

3. What will be the content of output.txt after this code runs?

# Assuming output.txt does not exist or is empty initially
with open("output.txt", "w") as f:
    f.write("First line\n")
    f.write("Second line")
 
 
 
 

4. What will be the output of the following print() function

print('%d %d %.2f' % (11, 22, 11.345))

 
 
 
 

5. What is the output of the following print() function

print('Mike', 'Sydney', sep='**')

 
 
 
 

6. Which of the following is the correct way to get integer input from the user and store it in a variable age

 
 
 
 

7. What will be the output of the following Python code?

print("Line 1", end="***")
print("Line 2")
 
 
 
 

8. What is the purpose of the flush=True argument in the print() function?

 
 
 
 

9. What will be the output of the following Python code?

print("The value is: {:0.2f}".format(12.3456))
 
 
 
 

10. What will be the output of print('[%c]' % 65)

 
 
 

11. Which mode should you use to open a file for writing, overwriting its contents if it already exists?

 
 
 
 

12. In Python 3, which functions is used to accept input from the user

 
 
 
 

13. What will be the output if the user types abc when prompted?

try:
    num = int(input("Enter a number: "))
    print(f"Number: {num}")
except ValueError:
    print("Invalid input!")
except TypeError:
    print("Type error!")
 
 
 
 

14. How can you redirect the output of a print() statement to a file instead of the console?

 
 
 
 

15. Which of the following is incorrect file handling mode in Python

 
 
 
 

16. Which standard library module is commonly used to “pretty print” complex data structures like dictionaries and lists in a more human-readable, indented format?

 
 
 
 

17. Use the following file to predict the correct output of the code

test.txt Content:

aaa
bbb
ccc
ddd
eee
fff
ggg

Code:

f = open("test.txt", "r")
print(f.readline(3))
f.close()

Hint: Read file in Python.

 
 
 
 

18. Input/Output Code Output Prediction (File I/O Scenario):

Assume data.txt contains:

Line 1
Line 2
Line 3

What will be the output of the following Python code?

with open("data.txt", "r") as f:
    first_line = f.readline()
    second_line = f.readline()
print(second_line.strip())
 
 
 
 

19. What is the primary advantage of using f-strings (formatted string literals) for output in Python 3.6+?

 
 
 
 

20. What is the output of the following print() function

print(sep='--', 'Ben', 25, 'California')

 
 
 
 

21. To take multiple space-separated inputs (e.g., 10 20 30) from a single line and convert them to integers in a list, which combination of methods is typically used?

 
 
 
 

22. In Python3, Whatever you enter as input, the input() function converts it into a string

 
 

23. What will be the output of the following code?

print('PYnative ', end='//')
print(' is for ', end='//')
print(' Python Lovers', end='//')
 
 
 
 

24. Which mode opens a file for both reading and writing, placing the file pointer at the beginning of the file?

 
 
 
 

25. Assume nums.txt contains:

12345

What will be the output of the following Python code?

with open("nums.txt", "r") as f:
    f.read(2)
    print(f.read(1))
 
 
 
 

Loading ... Loading …

Loading

Filed Under: Python, Python Basics, Python Quizzes

Did you find this page helpful? Let others know about it. Sharing helps me continue to create free Python resources.

TweetF  sharein  shareP  Pin

About Vishal

Image

I’m Vishal Hule, the Founder of PYnative.com. As a Python developer, I enjoy assisting students, developers, and learners. Follow me on Twitter.

Related Tutorial Topics:

Python Python Basics Python Quizzes

All Coding Exercises:

C Exercises
C++ Exercises
Python Exercises

Python Exercises and Quizzes

Free coding exercises and quizzes cover Python basics, data structure, data analytics, and more.

  • 15+ Topic-specific Exercises and Quizzes
  • Each Exercise contains 25+ questions
  • Each Quiz contains 25 MCQ
Exercises
Quizzes

Loading comments... Please wait.

In: Python Python Basics Python Quizzes
TweetF  sharein  shareP  Pin

  Python Quizzes

  • 15 Python Quizzes
  • Python Online MCQ Test
  • Basic Quiz For Beginners
  • Variables and Data Types Quiz
  • Functions Quiz
  • if else and loops Quiz
  • Numbers Quiz
  • String Quiz
  • List Quiz
  • Set Quiz
  • Dictionary Quiz
  • Tuple Quiz
  • Operators and Expression Quiz
  • Input and Output Quiz
  • Multithreading and Multiprocessing Quiz
  • File Handling Quiz
  • Random Data Generation Quiz

 Explore Python

  • Python Tutorials
  • Python Exercises
  • Python Quizzes
  • Python Interview Q&A
  • Python Programs

All Python Topics

Python Basics Python Exercises Python Quizzes Python Interview Python File Handling Python OOP Python Date and Time Python Random Python Regex Python Pandas Python Databases Python MySQL Python PostgreSQL Python SQLite Python JSON

About PYnative

PYnative.com is for Python lovers. Here, You can get Tutorials, Exercises, and Quizzes to practice and improve your Python skills.

Follow Us

To get New Python Tutorials, Exercises, and Quizzes

  • Twitter
  • Facebook
  • Sitemap

Explore Python

  • Learn Python
  • Python Basics
  • Python Databases
  • Python Exercises
  • Python Quizzes
  • Online Python Code Editor
  • Python Tricks

Coding Exercises

  • C Exercises
  • C++ Exercises
  • Python Exercises

Legal Stuff

  • About Us
  • Contact Us

We use cookies to improve your experience. While using PYnative, you agree to have read and accepted our:

  • Terms Of Use
  • Privacy Policy
  • Cookie Policy

Copyright © 2018–2025 pynative.com

Advertisement