Python
中的实时货币转换器
此
Python
程序包含一个简单的程序,用于使用外汇
Python
库
**
实时转换货币。
Forex
Python
库提供了通过
API
调用获取货币转换率的最直接方法。它有不同的功能,它们接
受您要从一种货币转换为另一种货币的货币代码,然后返回当前值。
在这个
Python
程序中,我们将美元转换为印度卢比。它将要求您输入要转换的金额和
货币代码。
Example:
An example of currency conversion using forex_ python:
from forex_python.converter import CurrencyRates
cr = CurrencyRates()
amount = int(input("Please enter the amount you want to convert:
"))
from_currency = input("Please enter the currency code that has to
be converted: ").upper()
to_currency = input("Please enter the currency code to convert:
").upper()
print("You are converting", amount, from_currency, "to",
to_currency,".")
output = cr.convert(from_currency, to_currency, amount)
print("The converted rate is:", output)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Program Output:
Please enter the amount you want to convert: 1
Please enter the currency code that has to be converted: USD
Please enter the currency code to convert: INR
You are converting 1 USD to INR.
The converted rate is: 77.58766511451107
评论0
最新资源