Untitled
unknown
plain_text
3 years ago
1.1 kB
8
Indexable
class ExchangeRate(object):
"""Documentation"""
conversion_rate = 0
def __init__(self, currency_name, currency_symbol):
self.currency_name = currency_name
self.currency_symbol = currency_symbol
@classmethod
def set_conversion_rate(cls, new_rate=0) -> float:
"""This method sets the class attribute conversion_rate"""
cls.conversion_rate = new_rate
return cls.conversion_rate
@classmethod
def convert_amount(cls, original_currency_value=0) -> float:
"""This method converts an original currency value to a foreign currency value"""
foreign_currency_value = cls.conversion_rate * original_currency_value
return foreign_currency_value
exchange_rate = ExchangeRate("Euro", "€")
print(ExchangeRate.set_conversion_rate.__doc__)
print(ExchangeRate.convert_amount.__doc__)
# Main program
saved_amount = 1800
eur_to_usd_rate = 1.08
ExchangeRate.set_conversion_rate(eur_to_usd_rate)
converted_amount = ExchangeRate.convert_amount(saved_amount)
print(f"Montant en euros: {saved_amount}€")
print(f"Montant en dollars: {converted_amount}$")
Editor is loading...