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