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. What is the output of the following print() function

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

 
 
 
 

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

 
 

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

 
 
 
 

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

 
 
 
 

5. What will be the output of  print('%x, %X' % (15, 15))

 
 
 
 

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

 
 
 
 

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

 
 
 
 

8. What is the recommended way to ensure a file is properly closed after you’re done with it, even if errors occur?

 
 
 
 

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 the following print() function

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

 
 
 
 

11. 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.

 
 
 
 

12. 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))
 
 
 
 

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

 
 
 
 

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

 
 
 
 

15. What is true for file mode 'x'

Hint: Create File in Python

 
 
 

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

 
 
 

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

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

 
 
 
 

18. What exception is typically raised when the input() function encounters an End-of-File (EOF) condition (e.g., when reading from a redirected file and there’s no more data)?

 
 
 
 

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

 
 
 
 

20. 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?

 
 
 
 

21. Which file mode would you use to add new content to the end of an existing file without deleting its current content?

 
 
 
 

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

 
 
 
 

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

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

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

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

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

Hint: File handling in Python.

 
 
 
 

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