Input and Output
Understand how to take user input and display output in Python programs.
Input and Output is a free Learn AI with Python lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Learn AI with Python learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
1
Introduction to Input and Output
Input and output are essential for interacting with a program. Input allows users to provide data, while output displays information back to them.
In this lesson, you’ll learn how to use the input() and print() functions in Python.

2
The print() Function
The print() function displays text or information on the screen. For example:
print("Hello, World!")
This will output:
Hello, World!# Using the print function
print("Hello, World!")3
The input() Function
The input() function allows users to enter data into a program. For example:
When you run this code, Python will prompt the user to enter their name and then greet them.
# Using the input function
name = input("What is your name? ")
print("Hello,", name)4
Combining Input and Output
You can combine the input() and print() functions to create interactive programs. For example:
# Combining input and output
age = input("How old are you? ")
print("You are", age, "years old!")5
Formatting Output
You can format output using the f-strings feature in Python. For example:
# Formatting output using f-strings
name = "Alice"
age = 25
print(f"{name} is {age} years old.")6
Using Input with Numbers
The input() function always returns a string, even if the user enters a number. You can convert it to an integer or float using int() or float(). For example:
# Using input with numbers
num = int(input("Enter a number: "))
print("Your number multiplied by 2 is", num * 2)7
Error Handling with Input
If the user enters invalid data, it can cause an error. You can handle such cases using a try-except block:
# Handling errors with input
try:
num = int(input("Enter a number: "))
print("Your number is", num)
except ValueError:
print("That’s not a valid number!")8
9
What Did We Learn?
In this lesson, you learned:
- How to use the
print()function to display output. - How to use the
input()function to take user input. - How to format output and handle input errors.
Great job! Let’s move to the next topic.

Frequently asked questions
Is the “Input and Output” lesson free?
Yes — the full text of “Input and Output” is free to read here on the web, and the Learn AI with Python course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Learn AI with Python course, upgrade to CoddyKit PRO.
What will I learn in “Input and Output”?
Understand how to take user input and display output in Python programs. You practise Learn AI with Python with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Learn AI with Python?
No prior experience is required. Learn AI with Python on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Input and Output” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Learn AI with Python lesson?
Yes. Every Learn AI with Python lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.