Simple Currency Converter
Convert between currencies with exchange rates.
IntermediatePhase 6 - Category 5: Real-World Logic ProblemsExample 7 of 15
simple-currency-converter.py
1# Exchange rates (example)2rates = {3 'USD': 1.0,4 'EUR': 0.85,5 'GBP': 0.73,6 'INR': 82.57}89# Take inputs10amount = float(input("Enter amount: "))11from_currency = input("From currency (USD/EUR/GBP/INR): ").upper()12to_currency = input("To currency (USD/EUR/GBP/INR): ").upper()1314# Convert15if from_currency in rates and to_currency in rates:16 # Convert to USD first, then to target17 usd_amount = amount / rates[from_currency]18 converted = usd_amount * rates[to_currency]19 print(f"{amount} {from_currency} = {converted:.2f} {to_currency}")20else:21 print("Invalid currency")
Output
Enter amount: 100 From currency (USD/EUR/GBP/INR): USD To currency (USD/EUR/GBP/INR): INR 100.0 USD = 8250.00 INR
What's going on
Convert using exchange rates.
Key Concepts:
Convert to base currency (USD)
Then convert to target currency
Use exchange rates
🔗Related Content
- 📖
Phase 6 - Learn Concepts
Review Phase 6 concepts and explanations
- 📝
Phase 6 - Quiz
Test your Phase 6 understanding with quiz questions
- 💻
Phase 6 - All Practice Problems
Explore all practice problems for Phase 6
- 🎓
Master Your Logic Building - Complete Course
Browse all phases and tutorials
- 🧠
Logic Building Overview
Learn about the complete logic building curriculum