Logic Building
# Exchange rates (example)
rates = {
'USD': 1.0,
'EUR': 0.85,
'GBP': 0.73,
'INR': 82.5
}
# Take inputs
amount = float(input("Enter amount: "))
from_currency = input("From currency (USD/EUR/GBP/INR): ").upper()
to_currency = input("To currency (USD/EUR/GBP/INR): ").upper()
# Convert
if from_currency in rates and to_currency in rates:
# Convert to USD first, then to target
usd_amount = amount / rates[from_currency]
converted = usd_amount * rates[to_currency]
print(f"{amount} {from_currency} = {converted:.2f} {to_currency}")
else:
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
Convert using exchange rates.
Key Concepts:
- Convert to base currency (USD)
- Then convert to target currency
- Use exchange rates