Python Lesson 5 – Input & Output | Dataplexa

Input and Output in Python

Every useful program does two basic things: it takes input (data) and produces output (results).

In this lesson, you will learn how Python prints information using print(), and how it receives user data using input().

Output with print()

The print() function displays text or values on the screen. It is one of the most used functions in Python.


# Basic output examples

print("Welcome to Dataplexa")
print(100)
print(10 + 5)
  
Welcome to Dataplexa
100
15
  • print("text") prints text (string).
  • print(100) prints a number.
  • print(10 + 5) prints the result of an expression.

Printing Multiple Values

You can print multiple items in one line. Python automatically adds a space between them.


# Printing multiple values

name = "Dataplexa"
year = 2026

print("Platform:", name)
print("Year:", year)
  
Platform: Dataplexa
Year: 2026
  • This style is clean and readable for beginners.
  • It is also useful for debugging while learning.

Controlling Output Formatting

Sometimes you want to control how text is printed. Two common options are:

  • sep → controls the separator between values
  • end → controls what to print at the end (default is a new line)

# sep and end examples

print("A", "B", "C", sep=" - ")
print("Loading", end="...")
print("Done")
  
A - B - C
Loading...Done
  • sep=" - " prints values with a custom separator.
  • end="..." prevents a new line and adds custom ending text.

Input with input()

The input() function reads text typed by the user. It always returns the input as a string.


# Taking input from the user

user_name = input("Enter your name: ")
print("Hello,", user_name)
  
Enter your name: Alex
Hello, Alex
  • The text inside input("...") is shown as a prompt.
  • The typed value is saved into a variable.

Important Note: input() Returns String

Because input() returns a string, numbers typed by the user must be converted before doing math.


# input() gives string, so we convert it

age_text = input("Enter your age: ")
age = int(age_text)   # convert string to integer

print("Next year, your age will be:", age + 1)
  
Enter your age: 24
Next year, your age will be: 25
  • int("24") converts a string into an integer.
  • After conversion, you can do math normally.

Real-World Example: Simple Billing Input

This example takes product price and quantity from the user, then prints a clear bill summary.


# Simple bill calculator using input and output

price = float(input("Enter price: "))      # convert to float for decimals
qty = int(input("Enter quantity: "))       # convert to int for whole count

subtotal = price * qty

print("Subtotal:", subtotal)
  
Enter price: 49.99
Enter quantity: 2
Subtotal: 99.98
  • float() is used for decimal values like prices.
  • int() is used for whole number values like quantity.
  • subtotal is calculated and displayed using print().

Practice

Which function is used to display output on the screen?

Which function is used to take user input from the keyboard?

By default, what type of value does input() return?

Which conversion function is commonly used for whole numbers?

Which conversion function is commonly used for decimal numbers?

Quick Quiz

Which parameter controls the separator between values in print()?




Which parameter controls what print() adds at the end of the output?




If a user types 10 and you want to add 5, which conversion do you need?




What is the default type returned by input()?




Recap: You learned how to display results using print(), how to take user input using input(), and how to convert input into numbers using int() and float().

Next up: Operators in Python.