Hello guys, Today in this code i discuss how to convert any currency in python.
This is an simple currency converter code.
First we have to download the currency data from the google and don't worry i will also provide
this file..
"currency data"
Argentine Peso 60.003324 0.016666
Australian Dollar 1.456434 0.686608
Bahraini Dinar 0.376000 2.659574
Botswana Pula 10.748595 0.093035
Brazilian Real 4.165726 0.240054
British Pound 0.769337 1.299820
Bruneian Dollar 1.347741 0.741982
Bulgarian Lev 1.764110 0.566858
Canadian Dollar 1.306715 0.765278
Chilean Peso 773.624384 0.001293
Chinese Yuan Renminbi 6.864835 0.145670
Colombian Peso 3332.909888 0.000300
Croatian Kuna 6.707817 0.149080
Czech Koruna 22.658193 0.044134
Danish Krone 6.740053 0.148367
Emirati Dirham 3.672500 0.272294
Euro 0.901975 1.108678
Hong Kong Dollar 7.769198 0.128713
Hungarian Forint 303.647304 0.003293
Icelandic Krona 123.937684 0.008069
Indian Rupee 71.105003 0.014064
Indonesian Rupiah 13639.488898 0.000073
Iranian Rial 42384.523271 0.000024
Israeli Shekel 3.456655 0.289297
Japanese Yen 110.186353 0.009076
Kazakhstani Tenge 377.052561 0.002652
Kuwaiti Dinar 0.303676 3.292982
Libyan Dinar 1.400173 0.714197
Malaysian Ringgit 4.060141 0.246297
Mauritian Rupee 36.510050 0.027390
Mexican Peso 18.652743 0.053611
Nepalese Rupee 114.301293 0.008749
New Zealand Dollar 1.512817 0.661018
Norwegian Krone 8.916480 0.112152
Omani Rial 0.384500 2.600780
Pakistani Rupee 154.783123 0.006461
Philippine Peso 50.963356 0.019622
Polish Zloty 3.827442 0.261271
Qatari Riyal 3.640000 0.274725
Romanian New Leu 4.311010 0.231964
Russian Ruble 61.558453 0.016245
Saudi Arabian Riyal 3.750000 0.266667
Singapore Dollar 1.347741 0.741982
South African Rand 14.539372 0.068779
South Korean Won 1160.078612 0.000862
Sri Lankan Rupee 181.329813 0.005515
Swedish Krona 9.524089 0.104997
Swiss Franc 0.968717 1.032293
Taiwan New Dollar 29.945199 0.033394
Thai Baht 30.350071 0.032949
Trinidadian Dollar 6.768242 0.147749
Turkish Lira 5.908338 0.169252
Venezuelan Bolivar 9.987500 0.100125
Now, copy the above code and save it as "currency data" in the same folder.
Then in the converter.py file first we have to open the file and read everylines via readlines(). Now, create an empty dictionary currencyDict.
Than we are splitting the line with a tab so that it can be easily parsed in the dictionary with key and value pairs.
When the user enter the amount which they want to convert than we multiply that amount to that currency which they want..
Here is the code if you have any doubt realated to this code please comment down below we are trying to resolve it as soon as possible..
"converter.py"
with open('currency data.txt') as f:
lines=f.readlines()
#print(a)
currencyDict={}
for line in lines:
parsed=line.split("\t")
#print(parsed)
#break
currencyDict[parsed[0]]=parsed[1]
#print(currencyDict)
amount=int(input("enter the amount you want to convert:="))
print("enter the currency you want to convert this amount..")
[print(item) for item in currencyDict.keys()]
currency=input("please enter one of these values:=")
print(f"{amount} INR is equal to {amount *float(currencyDict[currency])} {currency}")
If you have any doubt related to this than you can comment below i will definitely try my best to solve that..
Comments
Post a Comment