Skip to main content

User Input and Display ⌨️

Python User Input & Display is a core Python concept covering learn how to take user input in Python using the input() function and display it back with formatting. Master basic interaction. This topic is essential for academic learning, board exam preparation, and developing optimized real-world code.

Mentor's Note: A program that doesn't take input is like a radio—it only talks. A program that takes input is like a conversation! 💡


🌟 The Scenario: The Magic Mirror 🪞

Imagine you have a magic mirror that repeats whatever you say.

  • The Logic: You give it a word (Input). 📦
  • The Result: It shows you the word back (Output). ✅

💻 Implementation: The Greeting Lab

# 🛒 Scenario: Greeting a User
# 🚀 Action: Taking input and displaying it

# 1. Taking String Input (Text) 📛
name = input("Enter your name: ") # Prompts user and reads input as a string
print("Hello,", name + "!")

# 2. Taking Integer Input (Numbers) 🔢
# input() always returns a string, so we MUST convert it to an integer
number_str = input("Enter your favorite number: ")
number = int(number_str) # Convert the string to an integer
print(f"Your favorite number is: {number}")

📖 Key Concepts

  • input(): This function displays a message (the prompt) and waits for the user to type something and press Enter.
  • Always a String: Everything you type into input() is treated as text. If you want a number, you must convert it using int() or float().
  • f-strings: Using f"Text {variable}" is the modern, professional way to combine text and data in Python.

🧠 Step-by-Step Logic

  1. Start 🏁
  2. Prompt the user: "Enter your name: ".
  3. Wait for the user to type and press Enter.
  4. Store that value in the variable name.
  5. Display "Hello, " followed by the name.
  6. End 🏁

🎯 Practice Lab 🧪

Task: Age Calculator

Task: Ask the user for their birth year, calculate their age (2026 - birth_year), and print it. Hint: Don't forget to use int() for the year! 💡

Quick Quiz

Quick Quiz

If you type 10 into an input() prompt, what is the data type of the result?

  • int
  • str
  • float
  • boolean

Explanation: The input() function always returns a string (str), even if you type a number. You must use int(input()) to get an integer.



📈 Learning Path

📍 Visit Us

🏫 VD Computer Tuition Surat

VD Computer Tuition
📍 Address
2/66 Faram Street, Rustompura
Surat395002, Gujarat, India
📞 Phone / WhatsApp
+91 84604 41384
🌐 Website

Computer Classes & Tuition — Areas We Serve in Surat

AdajanAlthanAmroliAthwaAthwalinesBhagalBhatarBhestanCanal RoadChowkCitylightDumasGaurav PathGhod Dod RoadHaziraJahangirpuraKamrejKapodraKatargamLimbayatMagdallaMajura GateMota VarachhaNanpuraNew CitylightOlpadPalPandesaraParle PointPiplodPunaRanderRing RoadRustampuraSachinSalabatpuraSarthanaSosyo CircleUdhnaVarachhaVed RoadVesuVIP Road
📞 Call Sir💬 WhatsApp Sir