Skip to content

Python Programming! Input And Output | Lectures 3

A friendly robot sitting at a computer desk talking to a child

Lets Start Python Programming For Beginners. Input And Output, Lectures 3

🐍 Lecture 3: Input & Output

🎯 Goal

By the end of this lecture, you will:

  • Know how to get input from the user.
  • Be able to print messages and variables clearly.
  • Understand how to combine text and variables in print() statements.
  • Build a simple interactive program.

[adrotate banner=”3″]

πŸ’¬ What is Input & Output?

In programming:

  • Input means getting information from the user.
  • Output means showing information to the user.

We’ve already used output with the print() function. Now we’ll learn how to take input using input().

πŸ“₯ Getting Input with input()

The input() function asks the user for some information and stores it in a variable.

name = input("What is your name? ")
print("Hello,", name)

πŸ‘‰ When you run this, the computer will ask:

What is your name? 

You type your name and press Enter. Then it says:

Hello, Alice

πŸ§’ Kids Corner: Think of input() like asking a question to your robot friend and letting them write down the answer!

A friendly robot sitting at a computer desk talking to a child
A friendly robot sitting at a computer desk talking to a child

πŸ–¨οΈ Printing Variables and Text Together

There are a few easy ways to print text and variables together.

Method 1: Using commas (Simple)
name = "Emma"
print("Your name is", name)

πŸ‘‰ Output:

Your name is Emma

Python adds a space between the words automatically.

Method 2: Using f-strings (Best Way!)

An f-string lets you put variables directly into your message.

age = 10
print(f"I am {age} years old.")

πŸ‘‰ Output:

I am 10 years old.

Just add an f before the quotes and put the variable inside { }.

This is the most popular way to mix text and variables in Python!

πŸ§ͺ Try It Yourself!

Write a small program that:

  1. Asks for the user’s favorite color.
  2. Stores it in a variable.
  3. Prints a message like:

Wow! Blue is an awesome color!

πŸ’‘ Sample Code:
color = input("What is your favorite color? ")
print(f"Wow! {color} is an awesome color!")
βž• Combining Multiple Inputs

Let’s make a mini story using two inputs:

animal = input("Enter an animal: ")
color = input("Enter a color: ")

print(f"The {animal} saw a {color} balloon and got very excited!")
πŸ‘‰ Example Run:
Enter an animal: cat
Enter a color: red
The cat saw a red balloon and got very excited!

🧠 Type Conversion – Turning Input into Numbers

⚠️ Note: All input from input() is treated as text (str).
If you want to do math with it, you need to convert it to a number.

Example: Simple Calculator
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))

total = num1 + num2

print(f"The total is {total}")
πŸ‘‰ Run it:
Enter first number: 5
Enter second number: 7
The total is 12

Other conversions:

  • float() – for decimal numbers
  • str() – for turning numbers into text

πŸ§’ Kids Corner

πŸ€– Imagine your robot can talk AND listen!
Now it doesn’t just say things β€” it also hears what you say and remembers it.

πŸ’¬ Robot says:

Tell me your favorite food...
Okay, I remember it now!

πŸš€ Challenge (Optional)

Make a short quiz game that:

  1. Asks for the user’s name.
  2. Asks a fun question like β€œWhat is 5 + 3?”
  3. Checks if the answer is correct and gives feedback.

Example:

name = input("Welcome! What is your name? ")
answer = int(input("What is 5 + 3? "))

if answer == 8:
    print("Great job, " + name + "! You're a math wizard!")
else:
    print("Oops! The correct answer was 8.")

πŸ“Œ Summary

  • Use input() to get information from the user.
  • Use print() to show messages or variables.
  • Use f-strings to easily mix text and variables.
  • Convert input to numbers using int() or float() when needed.

πŸ”Ή Call Of Action

If this article was helpful to you, please Share and leave your feedback in the comment section below.

Python Programming For Beginners To Advanced

Python Programming For Beginners! Lecture 1

Python Programming! Variables and Data Types | Lectures 2

Python Programming! Input And Output | Lectures 3

Python Programming! Operators in Python Lectures 4

Python Programming! Conditional Statements Lectures 5

Najeeb Alam

Najeeb Alam

Technical writer specializes in developer, Blogging and Online Journalism. I have been working in this field for the last 20 years.

Leave a Reply

Your email address will not be published. Required fields are marked *