▶️ आगे: 10 Practice Problems — Input/Output (with Hints & Solutions)
Related: Python Operators in HindiPython String in Hindi

🧪 10 Practice Problems — Input/Output (with Hints & Solutions)

इन problems से आपकी python input output in hindi पकड़ मज़बूत होगी। हर कार्ड में Hint और Solution (Copy-बटन) शामिल है।

P1. दो संख्याओं का जोड़

User से दो numbers लें और sum print करें।

💡 Hint

int(input()) और +

✅ Solution
a = int(input("Enter A: "))
b = int(input("Enter B: "))
print("Sum =", a + b)

P2. One-line Calculator

Input: num1 num2 → sum, diff, prod, div print करें।

💡 Hint

map(float, input().split())

✅ Solution
x, y = map(float, input("Enter two numbers: ").split())
print("Sum:", x+y, "Diff:", x-y, "Prod:", x*y, "Div:", x/y)

P3. Personalized Greeting

Name और City लें → f-string से output दें।

💡 Hint

f”Hello {name} from {city}”

✅ Solution
name = input("Your name: ")
city = input("Your city: ")
print(f"Hello {name} from {city}! 👋")

P4. N Numbers का Average

Input: n फिर अगली लाइन में n numbers → average।

💡 Hint

sum(nums)/len(nums)

✅ Solution
n = int(input("How many numbers? "))
nums = list(map(float, input("Enter numbers: ").split()))
print("Average =", sum(nums)/n)

P5. Km → Miles (formatted)

Km लें और miles (2 decimals) print करें।

💡 Hint

1 km = 0.621371 miles; :.2f

✅ Solution
km = float(input("Enter km: "))
miles = km * 0.621371
print(f"{km:.2f} km = {miles:.2f} miles")

P6. Simple Interest

Input: P, R, T → SI = P*R*T/100; nicely format करें।

💡 Hint

f"₹{si:.2f}"

✅ Solution
P = float(input("Principal: "))
R = float(input("Rate (%): "))
T = float(input("Time (years): "))
si = P*R*T/100
print(f"Simple Interest = ₹{si:.2f}")

P7. Even Numbers Filter

Input list → सिर्फ even numbers को space-separated print करें।

💡 Hint

print(*evens) या " ".join()

✅ Solution
nums = list(map(int, input("Enter numbers: ").split()))
evens = [n for n in nums if n % 2 == 0]
print(*evens)

P8. टेबल-जैसा Output (Alignment)

तीन items लें और aligned columns में print करें।

💡 Hint

{text:^10}, {num:>6}

✅ Solution
items = [input("Item1: "), input("Item2: "), input("Item3: ")]
print(f"|{'Item':^10}|{'Len':>6}|")
for it in items:
    print(f"|{it:^10}|{len(it):>6}|")

P9. Valid Integer लो (त्रुटि-सुरक्षित)

जब तक user सही integer न दे, पूछते रहें।

💡 Hint

try/except ValueError

✅ Solution
while True:
    s = input("Enter an integer: ")
    try:
        n = int(s)
        break
    except ValueError:
        print("Invalid! Try again.")
print("You entered:", n)

P10. Progress Dots (end + flush)

एक लूप में dots दिखाएँ: ....done

💡 Hint

print(".", end="", flush=True)

✅ Solution
import time
for _ in range(5):
    print(".", end="", flush=True); time.sleep(0.3)
print("done")

❓ Python Input/Output — FAQ (Hindi, 2025 Updated)

Q1. input() क्या वापस करता है? Number कैसे लें?

input() हमेशा string लौटाता है। Number लेने के लिए type casting करें: int(input()), float(input()).

Q2. एक ही लाइन में multiple inputs कैसे लें?

a, b = input().split() या numbers के लिए: a, b = map(int, input().split()).

Q3. print() में sep और end क्या करते हैं?

sep arguments के बीच का separator है (डिफ़ॉल्ट space) और end लाइन के अंत में जोड़ने वाला text है (डिफ़ॉल्ट newline). जैसे: print(1,2,3, sep=",", end=";").

Q4. Output को formatted तरीके से कैसे दिखाएँ?

f-strings सबसे आसान हैं: f"Total: ₹{amount:.2f}". Alignment: {text:^10}, {num:>6}; Thousands separator: {n:,}.

Q5. फ़ाइल में output कैसे लिखें? Encoding का ध्यान?

with open("out.txt","w", encoding="utf-8") as f: print("नमस्ते", file=f). Unicode/हिंदी text के लिए encoding="utf-8" ज़रूर दें।

Q6. Console में progress/dots तुरंत कैसे दिखाएँ?

print(".", end="", flush=True) का उपयोग करें ताकि buffer तुरंत flush हो और output live दिखे।

🚀 अब आपकी बारी – Python Skills को अगले लेवल पर ले जाएँ!

आपने Python के input() और print() को अच्छे से सीख लिया है। अब आगे बढ़ें और File Handling, String Manipulation और Operators को मास्टर करें।

📂 Start Next: Python File Handling in Hindi
```html
📋 Get Course Details
```