Skip to content

Commit 32901ed

Browse files
authored
Create Converter-Converter.py
1 parent e9884b1 commit 32901ed

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
conversion_rates = {
2+
'USD': 1.0, # US Dollar
3+
'EUR': 0.95, # Euro
4+
'GBP': 0.82, # British Pound
5+
'JPY': 148.45, # Japanese Yen
6+
'CAD': 1.37, # Canadian Dollar
7+
'AUD': 1.57, # Australian Dollar
8+
'INR': 83.22, # Indian Rupee
9+
'CNY': 7.20, # Chinese Yuan
10+
'CHF': 0.92, # Swiss Franc
11+
'NZD': 1.68, # New Zealand Dollar
12+
'SEK': 11.03, # Swedish Krona
13+
'SGD': 1.37, # Singapore Dollar
14+
'HKD': 7.83, # Hong Kong Dollar
15+
'KRW': 1348.59, # South Korean Won
16+
'BRL': 5.16, # Brazilian Real
17+
'RUB': 99.55, # Russian Ruble
18+
'TRY': 13.55, # Turkish Lira
19+
'ZAR': 19.29, # South African Rand
20+
'MXN': 17.95, # Mexican Peso
21+
'AED': 3.67 # UAE Dirham
22+
}
23+
def convert_currency(amount, from_currency, to_currency):
24+
if from_currency == to_currency:
25+
return amount
26+
27+
if from_currency in conversion_rates and to_currency in conversion_rates:
28+
converted_amount = amount / conversion_rates[from_currency] * conversion_rates[to_currency]
29+
return converted_amount
30+
else:
31+
return None
32+
33+
amount = float(input("Enter the amount to convert: "))
34+
from_currency = input("Enter the source currency (e.g., USD): ").upper()
35+
to_currency = input("Enter the target currency (e.g., EUR): ").upper()
36+
37+
result = convert_currency(amount, from_currency, to_currency)
38+
39+
if result is not None:
40+
print(f"{amount} {from_currency} is equal to {result} {to_currency}")
41+
else:
42+
print("Invalid currency codes. Please check your input.")

0 commit comments

Comments
 (0)