</> Code Editor

Python Basic Input and Output Exercises


1/20

Python Basic Input and Output Practice Questions

Correct
0%

Which of the following functions is used in Python to display output on the screen?


In Python, the print() function is used to send output to the console. It can handle text, numbers, variables, and even multiple values at once.

Example:

print("Hello, World!")
print("Sum =", 5 + 3)

Why others are wrong:

  • Option 1 (display()) → Exists in Jupyter environments for rich display, not standard Python.
  • Option 2 (echo()) → Used in other languages/shells, not Python.
  • Option 3 (show()) → Sometimes used in libraries (like matplotlib), but not for general output.

Thus, print() is the standard and correct way for output in Python.

Quick Recap of Python Basic Input and Output Concepts

If you are not clear on the concepts of Basic Input and Output, you can quickly review them here before practicing the exercises. This recap highlights the essential points and logic to help you solve problems confidently.

What Is Output in Python?

You use the built-in print() function to display output on the screen.

print() can take multiple items (strings, variables, expressions) and separate them with commas. By default, it separates them with a space.

You can control how things are printed using keyword parameters:

  • sep: defines what string is put between the items.
  • end: defines what is added at the end (instead of the default newline \n).

Example:

first = "Python"
second = "Rocks"
print(first, second, sep=" -- ", end="!\n")
# Output: Python -- Rocks!

What Is Input in Python?

The input() function pauses your program and waits for the user to type something, then returns that as a string.

You can optionally provide a prompt inside input(...), which will be shown to the user before they type.

Example:

city = input("Where do you live? ")
print("You live in", city)

Converting User Input (Casting) in Python

Since input() always returns a string, you often need to convert (“cast”) that string into another type if you want to do calculations.

Use int() to convert to integer, float() to convert to decimal numbers.

Example:

age_str = input("Enter your age: ")
age = int(age_str)
print("In five years, you will be", age + 5)

Be careful: if the user types something that can’t be converted (like “abc”), it will cause an error at runtime. Good programs should check or validate input before casting.

Taking Multiple Inputs in Python

You can read more than one value from a single input() call by using .split() to divide the input string into parts.

Example:

x, y = input("Enter two numbers separated by space: ").split()
x = int(x)
y = int(y)
print("First:", x, "Second:", y)

Advanced print() Parameters & Behavior in Python

print() supports more than just sep and end: you can also redirect output with file or flush the output buffer with flush.

Example of using end in a loop, to print items on the same line:

for i in range(5):
    print(i, end=" ")
print()  # This moves to the next line afterward
# Output: 0 1 2 3 4

Best Practices & Tips for Input & Output in Python

  • Always provide a clear prompt in input() so users understand what they need to type.

  • Validate or sanitize user input before converting it to a number to avoid runtime errors.
  • Use formatting (like f-strings) to make your print output cleaner and more readable.
  • Be careful with long or complex inputs — splitting, converting, and handling them properly makes your program more robust.


About This Exercise: Python – Basic Input and Output

Welcome to our Python Basic Input and Output exercises on Solviyo. We’ve carefully designed this collection of challenges to help learners build a strong understanding of how programs interact with users. Input and output are among the first skills every programmer needs to master, and through these exercises, you’ll gain both clarity and confidence.

In Python, input allows programs to collect information from users, while output displays meaningful results back to them. In these exercises, you’ll practice using the input() function to read data, experiment with the print() function to format results, and learn how to handle both text and numeric values effectively. We also include tasks that show you how to format strings using f-strings and other methods, ensuring your output is both clean and professional.

The exercises begin with simple challenges like reading a line of text and echoing it back. As you progress, you’ll work on combining multiple variables into a single result, performing calculations with numeric input, and formatting your output neatly for better readability. Since Python reads input as strings by default, you’ll also practice type conversion so you can correctly handle numbers, strings, and mixed data.

At Solviyo, we want learning to feel practical and relevant. That’s why the exercises are inspired by real-world situations, such as asking users for personal details, calculating totals, or displaying formatted results. These everyday scenarios make learning interactive and show how input and output form the backbone of any application.

By practicing consistently, you’ll gain an intuitive understanding of how Python communicates with users. This foundation will prepare you for more advanced areas such as file handling, error checking, and building interactive applications. Each exercise comes with explanations so you can learn from mistakes, reinforce concepts, and apply them in your own projects.

Whether you’re just beginning your Python journey or revisiting the basics, these input and output exercises will sharpen your problem-solving skills and improve your coding style. Start practicing with Solviyo today, and see how simple, interactive programs can transform into the building blocks for more advanced Python development.