Input From User

Nerd Cafe | نرد کافه

1. What is User Input in Python?

Definition:

User input means taking data from a human (the user) while the program is running. In Python, this is done using the input() function.

Syntax:

input("Prompt message")
  • "Prompt message" is optional text shown to the user as a guide.

  • The input is always stored as a string, even if the user types a number.

👉 If you need numbers, you must convert them using int(), float(), etc.

2. Basic Input Example

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

Output:

What is your name? Alice
Hello, Alice

💡 Example in practice:

  • If you are making a login screen, you can ask for a username or email address using input.

3. Input with Conversion (Numbers)

Integers

Output:

⚠️ Practical Note: If the user types a word (like "twenty"), the program will crash. We’ll learn how to fix that using error handling later.

Floats (Decimal Numbers)

Output:

4. Taking Multiple Inputs at Once

You can ask the user to enter multiple values in one line, separated by spaces (or commas).

Output:

👉 .split() breaks input into pieces (default: space).

Example with commas:

Output:

5. Summary Table

Purpose
Code Example
Notes

Basic text input

name = input("Name: ")

Always returns a string

Number input

num = int(input()) / float(input())

Must convert to numeric types

Multiple inputs

a, b = input().split()

.split() separates by spaces

6. Video Tutorial

💖 Support Our Work

If you find this post helpful and would like to support my work, you can send a donation via TRC-20 (USDT). Your contributions help us keep creating and sharing more valuable content.

Thank you for your generosity! 🙏

Keywords

input, print, string, integer, float, split, list, tuple, dictionary, try, except, while, if, else, conversion, error, prompt, nerd cafe , نرد کافه

Channel Overview

🌐 Website: www.nerd-cafe.ir

📺 YouTube: @nerd-cafe

🎥 Aparat: nerd_cafe

📌 Pinterest: nerd_cafe

📱 Telegram: @nerd_cafe

📝 Blog: Nerd Café on Virgool

💻 GitHub: nerd-cafe

Last updated