-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
50 lines (36 loc) · 1.43 KB
/
main.py
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import forex_python.converter
from forex_python.converter import CurrencyRates, CurrencyCodes
import datetime
converter = CurrencyRates()
codes = CurrencyCodes()
valueFrom = input("Enter the value you want to convert: ")
currencyFrom = input("Enter the currency you want to convert: ").upper()
print(valueFrom+' '+currencyFrom)
base_symbol = codes.get_symbol(currencyFrom.upper())
def check_symbol(symbol, currency):
while symbol is None:
print('The entered symbol is invalid')
currency = input("Enter the currency: ").upper()
symbol = codes.get_symbol(currency.upper())
if symbol is not None:
return symbol
base_symbol = check_symbol(base_symbol, currencyFrom)
print(valueFrom,base_symbol)
currencyTo = input("Enter the currency you want to get: ").upper()
print(currencyTo)
to_symbol = codes.get_symbol(currencyTo.upper())
to_symbol = check_symbol(to_symbol, currencyTo)
print(to_symbol)
today = datetime.date.today()
print("Date of today : ", today)
global rate
try:
rate = converter.get_rate(currencyFrom, currencyTo, today)
# rate = c.get_rate("USD", "EUR")
# The exchange rate is a floating-point number
# that represents the number of Euros that you can get for one US dollar.
print(rate)
total = float(rate) * float(valueFrom)
print(valueFrom, currencyFrom, " is ", total, currencyTo)
except forex_python.converter.RatesNotAvailableError as e:
print("Exception: ", e)