Advertisement
Rnery

conversão de dinheiro..

May 4th, 2024
786
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | Cryptocurrency | 0 0
  1. from locale import setlocale, currency, Error
  2.  
  3. class Dinheiro:
  4.     def __init__(self, valor):
  5.         self.valor = valor
  6.  
  7.     def converter_para_moeda(self, moeda):
  8.         try:
  9.             setlocale(locale.LC_ALL, moeda)
  10.             return currency(self.valor, grouping=True)
  11.         except Error:
  12.             return f"Moeda não suportada: {moeda}"
  13.  
  14. # Exemplo de uso:
  15. valor_em_reais = 300
  16. dinheiro = Dinheiro(valor_em_reais)
  17.  
  18. print(f"Reais: {dinheiro.converter_para_moeda('pt_BR')}")
  19. print(f"Dólar: {dinheiro.converter_para_moeda('en_US')}")
  20. print(f"Euro: {dinheiro.converter_para_moeda('de_DE')}")
  21. print(f"Libra Esterlina: {dinheiro.converter_para_moeda('en_GB')}")
  22. print(f"Iene Japonês: {dinheiro.converter_para_moeda('ja_JP')}")
  23. print(f"Dólar Australiano: {dinheiro.converter_para_moeda('en_AU')}")
  24. print(f"Franco Suíço: {dinheiro.converter_para_moeda('fr_CH')}")
  25.  
Tags: python moeda
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement