-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP8
More file actions
31 lines (26 loc) · 955 Bytes
/
Copy pathP8
File metadata and controls
31 lines (26 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Predefined exchange rates (base: USD)
exchange_rates = {
'USD': 1.0,
'EUR': 0.85,
'INR': 83.2,
'JPY': 110.0,
'GBP': 0.75,
'AUD': 1.35
}
def convert_currency(amount, from_currency, to_currency):
if from_currency not in exchange_rates or to_currency not in exchange_rates:
return None
usd_amount = amount / exchange_rates[from_currency] # Convert to USD
converted_amount = usd_amount * exchange_rates[to_currency]
return converted_amount
# --- User Interface ---
print("Currency Converter (Offline - Predefined Rates)\n")
print("Available currencies:", ', '.join(exchange_rates.keys()))
amount = float(input("Enter amount: "))
from_curr = input("From currency: ").upper()
to_curr = input("To currency: ").upper()
result = convert_currency(amount, from_curr, to_curr)
if result is not None:
print(f"\n{amount} {from_curr} = {round(result, 2)} {to_curr}")
else:
print("Currency not supported.")