Online Computer Courses Classes and Training Program

Python Input Function in Hindi | input(), int(), float(), str() Complete Guide Part 4

Python Input Function in Hindi


Python Input Function (input()), Type Conversion और पहला Interactive Program | Complete Python Tutorial in Hindi – Part 4



Introduction

अब तक हमने Python में Program लिखना, Variables और Data Types सीखे।

लेकिन अभी तक हमारे सभी Programs Fixed थे।

उदाहरण के लिए—

name = "Ajay"

print(name)

हर बार Program केवल Ajay ही Print करेगा।

लेकिन यदि User अपना नाम स्वयं दर्ज करना चाहे तो?

यहीं से शुरू होता है Interactive Programming

इस अध्याय में हम सीखेंगे—

  • input() Function
  • User से Data लेना
  • String Input
  • Number Input
  • Type Conversion
  • int()
  • float()
  • str()
  • Practical Programs
  • Common Errors

Interactive Program क्या होता है?

जो Program User से जानकारी लेकर उसके अनुसार Result देता है, उसे Interactive Program कहते हैं।

उदाहरण—

Calculator

ATM Machine

Login Form

Registration Form

Online Shopping Website

ये सभी User से Input लेते हैं।


input() Function क्या है?

Python में User से Data लेने के लिए

input()

Function का उपयोग किया जाता है।

Syntax

variable = input("Message")

पहला Input Program

name = input("Enter Your Name : ")

print(name)

Output

Enter Your Name : Ajay

Ajay

Input कैसे काम करता है?

Step 1

Program Message दिखाता है।

Enter Your Name :

Step 2

User Keyboard से Data लिखता है।

Ajay

Step 3

Python उस Value को Variable में Store कर देता है।


Message क्यों लिखते हैं?

यदि Message नहीं लिखेंगे—

name = input()

तो User को समझ नहीं आएगा कि क्या लिखना है।

इसलिए हमेशा Message दें।

सही तरीका

name = input("Enter Your Name : ")

User का नाम Print करना

name = input("Enter Name : ")

print("Welcome", name)

Output

Enter Name : Rahul

Welcome Rahul

User की City लेना

city = input("Enter City : ")

print("City :", city)

ध्यान देने वाली बात

Python में

input()

हमेशा String Return करता है।

चाहे User Number ही क्यों न लिखे।

उदाहरण

age = input("Enter Age : ")

print(type(age))

Output

<class 'str'>

यह Integer नहीं बल्कि String है।


यदि Number चाहिए तो?

मान लीजिए User से Age लेनी है।

age = input("Enter Age : ")

यदि आप लिखेंगे—

print(age + 5)

तो Error आएगा।

क्योंकि

Age = String

5 = Integer

दोनों अलग-अलग Data Types हैं।


Type Conversion क्या है?

एक Data Type को दूसरे Data Type में बदलना Type Conversion कहलाता है।

उदाहरण—

String → Integer

Integer → Float

Float → String


int() Function

String को Integer में बदलने के लिए

int()

का उपयोग करते हैं।

उदाहरण

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

print(age)

अब

print(type(age))

Output

<class 'int'>

अब Calculation करें

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

print(age + 5)

Input

20

Output

25

float() Function

Decimal Number लेने के लिए

price = float(input("Enter Price : "))

यदि User लिखता है—

199.99

तो

print(price)

Output

199.99

str() Function

किसी भी Value को String में बदलने के लिए

str()

का उपयोग करते हैं।

उदाहरण

number = 100

text = str(number)

print(type(text))

Output

<class 'str'>

Example 1

User का नाम और उम्र लेना

name = input("Enter Name : ")

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

print("Name :", name)

print("Age :", age)

Example 2

दो Numbers जोड़ना

a = int(input("Enter First Number : "))

b = int(input("Enter Second Number : "))

print("Sum =", a+b)

Input

10

20

Output

Sum = 30

Example 3

Rectangle का Area

Formula

Area = Length × Width

length = float(input("Length : "))

width = float(input("Width : "))

area = length * width

print("Area =", area)

Example 4

Student Information

name = input("Student Name : ")

course = input("Course : ")

age = int(input("Age : "))

print("Student")

print(name)

print(course)

print(age)

Example 5

Simple Interest

Formula

SI = (P × R × T) / 100

p = float(input("Principal : "))

r = float(input("Rate : "))

t = float(input("Time : "))

si = (p*r*t)/100

print("Simple Interest =", si)

Common Errors

Error 1

age = input()

print(age+5)

Error

क्योंकि age String है।


सही

age = int(input())

print(age+5)

Error 2

User ने लिखा

Twenty

लेकिन Program

int(input())

Use कर रहा है।

तो Error आएगा।

क्योंकि

Twenty

Integer नहीं है।


Error 3

Float की जगह

int()

Use करना

यदि User लिखे—

99.99

तो

int("99.99")

Error देगा।

इसलिए

float()

Use करें।


Mini Project

Age Calculator

name = input("Name : ")

birth = int(input("Birth Year : "))

current = 2026

age = current-birth

print(name)

print(age)

Mini Project

BMI Input

weight = float(input("Weight : "))

height = float(input("Height : "))

bmi = weight/(height*height)

print("BMI =", bmi)

Practice Programs

Program 1

User से नाम लेकर Welcome Message दिखाइए।

Program 2

दो Numbers जोड़िए।

Program 3

तीन Numbers का Average निकालिए।

Program 4

Circle का Area निकालिए।

Program 5

Temperature Celsius से Fahrenheit में बदलिए।

Program 6

Student Percentage Calculator बनाइए।

Program 7

Salary Calculator बनाइए।


Interview Questions

  • input() Function क्या करता है?
  • input() किस Data Type में Value Return करता है?
  • int() और float() में क्या अंतर है?
  • Type Conversion क्या है?
  • String को Integer कैसे बनाते हैं?
  • Integer को String कैसे बनाते हैं?
  • User Input लेते समय सबसे सामान्य गलती क्या होती है?

Summary

इस अध्याय में आपने सीखा—

  • Interactive Program क्या होता है
  • input() Function
  • User से Data लेना
  • String Input
  • Integer Input
  • Float Input
  • Type Conversion
  • int()
  • float()
  • str()
  • Practical Examples
  • Common Errors
  • Mini Projects
  • Practice Programs

अब आप ऐसे Python Programs बना सकते हैं जो User से जानकारी लेकर उसके अनुसार Result दिखाएँ। यही वास्तविक Programming की शुरुआत है।


अगले अध्याय में क्या सीखेंगे?

Part 5 – Python Operators (Arithmetic, Assignment, Comparison, Logical, Membership, Identity और Bitwise Operators) को आसान उदाहरणों और Practical Programs के साथ विस्तार से समझेंगे।


Post a Comment

0 Comments