Intro
Aapne picchle post mein input() use kiya. Bahut badi baat.
Ab ek chhota sa twist: input() hamesha text (string) deta hai.
Isliye aaj hum sikhenge: text ko number kaise banate hain, aur number ko text kaise banate hain.
Concept Explanation
WHY: Type conversion ki zaroorat kyun hoti hai?
Socho aapne user se bola: “Apni age likho”.
User ne likha: 10
Python ne usko number nahi maana. Python ne usko text maana.
Matlab "10".
Ab problem dekho:
"10" + "5"ka matlab hota hai text jodna →"105"10 + 5ka matlab hota hai math →15
Python ko clearly bataana padta hai:
“Ye wali cheez number hai” ya “ye wali cheez text hai”.
Isi ko kehte hain type conversion (ya casting).
HOW: Teen important converters
- int()– Jab aapko whole number chahiye (0, 1, 2, 10, 99)
- float() -Jab aapko decimal number chahiye (2.5, 10.75)
- str()– Jab aapko number ko text banake print karna ho (especially message ke saath jodna ho)
Rule yaad rakho (Blackboard rule)
input()→ string- Math karna hai → pehle
int()yafloat() - Message me number jodna hai →
str()
Common mistake (jo beginners karte hain)
Aap int("12.5") karoge to error aayega, kyunki "12.5" decimal hai.
Us case me pehle float("12.5") banana hota hai.
Example
Example 1: Age me 1 add karna
User age dega. Hum next year ki age nikalenge.
# Lesson 9 - Example 1: int() use karke age ko number banana
age_text = input("Enter your age: ")
age = int(age_text)
next_year_age = age + 1
print("Next year your age will be:", next_year_age)
Example 2: Price me total nikalna (float)
Agar chocolate 12.50 ki hai aur aap 2 loge, total nikalenge.
# Lesson 9 - Example 2: float() use karke price ko decimal banana
price_text = input("Enter price of one chocolate (example 12.50): ")
price = float(price_text)
total = price * 2
print("Total price for 2 chocolates:", total)
Try It Yourself
- User se “marks” lo (0–100).
- Use
int()me convert karo. - Print karo: “Your marks are …” (yahan
str()ka use karo).
# Lesson 9 - Example 3: str() use karke number ko text banana
marks = 95
print("Your marks are " + str(marks))
Summary
input()hamesha string deta hai.int()whole number banata hai.float()decimal number banata hai.str()number ko text banata hai, taaki message ke saath jod sako.
Next
Next hum numbers ke saath basic math operators (+ - * /) practice karenge.

