TGViewer
Artificial Intelligence Artificial Intelligence @machinelearning_deeplearning · 56.3K subscribers
Post #1856 3.38K
In the previous post, we learned about Python data types and how different kinds of data are stored. Now, let's learn how to interact with users by taking input and displaying output.

📖 Phase 1: Programming Fundamentals

📌 Topic 6: Input & Output

Every program performs two basic operations:

• Input – Receiving data from the user.

• Output – Displaying information to the user.

For example, when you enter your username and password on a website, that's input. When the website displays "Login Successful," that's output.

Output in Python

Python uses the print() function to display output on the screen.

Example:

print("Hello, World!")

Output:

Hello, World!

You can also print numbers and variables.

name = "Surya"

age = 25

print(name)

print(age)

Output:

Surya

25

Printing Multiple Values

name = "Ajay"

age = 25

print("Name:", name)

print("Age:", age)

Output:

Name: Ajay

Age: 25

Input in Python

Python uses the input() function to accept input from the user.

Example:

name = input("Enter your name: ")

print("Hello,", name)

Sample Output:

Enter your name: Deepak

Hello, Deepak

Taking Numeric Input

By default, input() returns a string.

age = input("Enter your age: ")

print(type(age)) #

To use it as a number, convert with int() or float().

age = int(input("Enter your age: "))

Example: Adding Two Numbers

num1 = int(input("Enter first number: "))

num2 = int(input("Enter second number: "))

sum = num1 + num2

print("Sum =", sum)

Sample Output:

Enter first number: 10

Enter second number: 20

Sum = 30

Common Beginner Mistakes

❌ Forgetting that input() always returns a string.

❌ Trying to add two numbers without converting them.

num1 = input("Enter first number: ")

num2 = input("Enter second number: ")

print(num1 + num2)

If user enters 10 and 20 → Output: 1020

This happens because Python joins two strings instead of adding two numbers.

Best Practices

✅ Use clear prompts while taking input.

✅ Convert numeric input using int() or float() whenever required.

✅ Use meaningful variable names.

Key Takeaways

• print() is used to display output.

• input() is used to receive input from the user.

• input() always returns a string.

• Convert user input using int() or float() for mathematical operations.

• Input and Output are the foundation of interactive Python programs.

➡️ Double Tap ❤️ For More
  • ❤ 22
  • 👏 1
More from @machinelearning_deeplearning
  1. Sep 22, 2026🚀 Welcome back to our AI Engineer Roadmap! ❤️ In the previous posts, we learned about fun…
  2. Sep 21, 2026🚀 Welcome back to our AI Engineer Roadmap! ❤️ In the previous post, we explored functions…
  3. Sep 20, 2026In the previous post, we learned how conditional statements allow Python programs to make…
  4. Sep 19, 2026In the previous post, we explored Python operators and even tested ourselves with some tri…
  5. Sep 18, 2026In the previous post, we learned how to convert one data type into another using Type Cast…
  6. Sep 17, 2026In the previous post, we learned how to take input from users and display output. One impo…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →