इन problems से आपकी python input output in hindi पकड़ मज़बूत होगी। हर कार्ड में Hint और Solution (Copy-बटन) शामिल है।
User से दो numbers लें और sum print करें।
int(input()) और +
a = int(input("Enter A: "))
b = int(input("Enter B: "))
print("Sum =", a + b)
Input: num1 num2 → sum, diff, prod, div print करें।
map(float, input().split())
x, y = map(float, input("Enter two numbers: ").split())
print("Sum:", x+y, "Diff:", x-y, "Prod:", x*y, "Div:", x/y)
Name और City लें → f-string से output दें।
f”Hello {name} from {city}”
name = input("Your name: ")
city = input("Your city: ")
print(f"Hello {name} from {city}! 👋")
Input: n फिर अगली लाइन में n numbers → average।
sum(nums)/len(nums)
n = int(input("How many numbers? "))
nums = list(map(float, input("Enter numbers: ").split()))
print("Average =", sum(nums)/n)
Km लें और miles (2 decimals) print करें।
1 km = 0.621371 miles; :.2f
km = float(input("Enter km: "))
miles = km * 0.621371
print(f"{km:.2f} km = {miles:.2f} miles")
Input: P, R, T → SI = P*R*T/100; nicely format करें।
f"₹{si:.2f}"
P = float(input("Principal: "))
R = float(input("Rate (%): "))
T = float(input("Time (years): "))
si = P*R*T/100
print(f"Simple Interest = ₹{si:.2f}")
Input list → सिर्फ even numbers को space-separated print करें।
print(*evens) या " ".join()
nums = list(map(int, input("Enter numbers: ").split()))
evens = [n for n in nums if n % 2 == 0]
print(*evens)
तीन items लें और aligned columns में print करें।
{text:^10}, {num:>6}
items = [input("Item1: "), input("Item2: "), input("Item3: ")]
print(f"|{'Item':^10}|{'Len':>6}|")
for it in items:
print(f"|{it:^10}|{len(it):>6}|")
जब तक user सही integer न दे, पूछते रहें।
try/except ValueError
while True:
s = input("Enter an integer: ")
try:
n = int(s)
break
except ValueError:
print("Invalid! Try again.")
print("You entered:", n)
एक लूप में dots दिखाएँ: ....done
print(".", end="", flush=True)
import time
for _ in range(5):
print(".", end="", flush=True); time.sleep(0.3)
print("done")
input() क्या वापस करता है? Number कैसे लें?
input() हमेशा string लौटाता है। Number लेने के लिए type casting करें:
int(input()), float(input()).
a, b = input().split() या numbers के लिए:
a, b = map(int, input().split()).
print() में sep और end क्या करते हैं?
sep arguments के बीच का separator है (डिफ़ॉल्ट space) और end लाइन के अंत में जोड़ने वाला text है
(डिफ़ॉल्ट newline). जैसे: print(1,2,3, sep=",", end=";").
f-strings सबसे आसान हैं: f"Total: ₹{amount:.2f}". Alignment:
{text:^10}, {num:>6}; Thousands separator: {n:,}.
with open("out.txt","w", encoding="utf-8") as f: print("नमस्ते", file=f).
Unicode/हिंदी text के लिए encoding="utf-8" ज़रूर दें।
print(".", end="", flush=True) का उपयोग करें ताकि buffer तुरंत flush हो और output live दिखे।
आपने Python के input() और print() को अच्छे से सीख लिया है। अब आगे बढ़ें और File Handling, String Manipulation और Operators को मास्टर करें।
📂 Start Next: Python File Handling in Hindi