🏠 Home 📚 Chapters 💻 Projects ℹ️ About
HomeProjects › Day 07
DAY 07 — 60 DAY PYTHON CHALLENGE

💻 Unit Converter

Python में Unit Converter — km, mile, kg, pound हिंदी में

Advertisement

Complete Code

python — day07.py
def unit_converter():
    print("📏 Unit Converter")
    print("1. KM → Mile    2. Mile → KM")
    print("3. Meter → Feet  4. Feet → Meter")
    print("5. KG → Pound   6. Pound → KG")
    print("7. Liter → Gallon")

    try:
        choice = int(input("\nChoice (1-7): "))
        value  = float(input("Value: "))

        conversions = {
            1: (value * 0.621371,  "KM",    "Mile"),
            2: (value * 1.60934,   "Mile",  "KM"),
            3: (value * 3.28084,   "Meter", "Feet"),
            4: (value / 3.28084,   "Feet",  "Meter"),
            5: (value * 2.20462,   "KG",    "Pound"),
            6: (value / 2.20462,   "Pound", "KG"),
            7: (value * 0.264172,  "Liter", "Gallon"),
        }

        if choice in conversions:
            result, f, t = conversions[choice]
            print(f"\n✅ {value} {f} = {result:.4f} {t}")
        else:
            print("❌ 1-7 में से चुनें!")
    except ValueError:
        print("❌ सही number डालें!")

unit_converter()
OUTPUT
📏 Unit Converter Choice (1-7): 1 Value: 10 ✅ 10.0 KM = 6.2137 Mile

यह Code कैसे काम करता है?

Dictionary में सब conversion factors store हैं। tuple unpacking से result, from_unit, to_unit एक साथ मिलते हैं। :.4f से 4 decimal places दिखते हैं।
Advertisement

📋 Project ka Introduction

Unit Converter Python ka Day 7 ka project hai. Is project mein aap Python ke important concepts practice karenge jo real-world applications mein bahut use hote hain.

Yeh project beginners ke liye design kiya gaya hai lekin kaafi concepts cover karta hai. Step by step samjho, code chalao, aur khud modify karke practice karo.

Is tarah ke projects banane se aapka Python confidence badh jaata hai aur aap asli problems solve karna seekh jaate hain. Chaliye code samjhte hain!

🧠 Is Project mein kya seekhoge?

Yeh project banate waqt aap ye Python concepts use karoge:
ConceptKya karta hai
VariablesData store karna
FunctionsReusable code blocks
LoopsRepeat karna
ConditionsDecisions lena
Input/OutputUser se interact karna

📝 Code kaise kaam karta hai — Step by Step

Neeche code ki poori logic step-by-step samjhayi gayi hai:
  1. Problem samjho: Unit Converter mein kya karna hai
  2. Required variables aur data structures decide karo
  3. Logic step-by-step likhó
  4. Code mein implement karo
  5. Test karo aur bugs fix karo

⚠️ Common Mistakes — Bhool mat jaana!

Beginners yeh galtiyan aksar karte hain — dhyan rakho:
  • ⚠️ Indentation sahi rakho — Python mein spaces matter karti hain
  • ⚠️ Variables ko use se pehle define karo
  • ⚠️ Input ko int()/float() mein convert karo agar number chahiye
  • ⚠️ Edge cases handle karo — kya hoga agar user galat input de?

🏋️ Practice Exercises — Aage badho!

Yeh project complete karne ke baad in exercises se practice karo:
  • 💡 Unit Converter mein naya feature add karo
  • 💡 Code ko functions mein refactor karo
  • 💡 Error handling improve karo
  • 💡 File mein data save karo

❓ Aksar Pooche Jane Wale Sawal (FAQ)

Q: Unit Converter project kyon banana chahiye?

A: Har project ek naya concept sikhata hai. Practice se hi Python fluent aati hai.
Q: Code run nahi ho raha?

A: Indentation check karo, syntax errors dekho, variables define hain ya nahi check karo.
Q: Kaise improve karein?

A: Pehle basic version complete karo, phir ek ek feature add karte jao.