当前位置:首页 > 外汇 > 正文

外汇牌价换算器

外汇牌价换算器

以下是一个简单的外汇牌价换算器的示例代码,使用Python编写。这个例子中,我们假设有一个固定的汇率表,你可以根据实际情况更新汇率。```pythonclass Cur...

以下是一个简单的外汇牌价换算器的示例代码,使用Python编写。这个例子中,我们假设有一个固定的汇率表,你可以根据实际情况更新汇率。

```python

class CurrencyConverter:

def __init__(self, exchange_rates):

self.exchange_rates = exchange_rates

def convert(self, from_currency, to_currency, amount):

if from_currency == to_currency:

return amount

if from_currency in self.exchange_rates and to_currency in self.exchange_rates:

return amount self.exchange_rates[to_currency] / self.exchange_rates[from_currency]

else:

return "Currency not supported."

示例汇率表

exchange_rates = {

'USD': 1.0, 美元为基准

'EUR': 0.9, 欧元

'JPY': 110.0, 日元

'GBP': 0.8, 英镑

'CNY': 6.5 人民币

最新文章

随机文章