from enum import Enum
[docs]
class Currency(Enum):
"""Supported currencies with their symbols and USD conversion rate.
Attributes:
USD (Currency): US Dollar, symbol "$", conversion rate to USD is 1.0.
EUR (Currency): Euro, symbol "€", conversion rate to USD is 1.15.
"""
USD = "$"
EUR = "€"
[docs]
def __init__(self, symbol: str):
"""Initialize the currency with its symbol and set its USD conversion rate.
Args:
symbol (str): The symbol representing the currency.
Raises:
ValueError: If the currency is unsupported.
"""
self.symbol = symbol
if self.name == "EUR":
self.value_in_usd = 1.15
elif self.name == "USD":
self.value_in_usd = 1.0
else:
raise ValueError(f"Unsupported currency: {self.name}")
def __repr__(self):
"""Return the symbol of the currency."""
return self.symbol