fork download
  1. plan = [
  2. [2000.0, 2000.0, 2000.0, 2000.0, 2000.0, 2000.0],
  3. [2000.0, 2000.0, 2000.0, 2000.0, 2000.0, 2000.0, 2000.0],
  4. [2000.0, 2000.0, 1250.0, 1250.0, 1250.0, 1250.0, 1250.0],
  5. [1250.0, 1250.0, 1250.0, 1250.0, 1250.0, 1250.0, 1250.0],
  6. [1250.0, 1250.0, 1250.0]
  7. ]
  8.  
  9. from itertools import zip_longest
  10.  
  11. def formata(n, casas_decimais):
  12. try:
  13. return f'{float(n):.{casas_decimais}f}'
  14. except ValueError:
  15. return n
  16.  
  17. tamanho = 15
  18. # o "size" na string abaixo é substituído pelo valor da variável "tamanho"
  19. print(('{:<{size}}' * len(plan)).format(*map(lambda x: f'{x + 1}º PERÍODO', range(len(plan))), size=tamanho))
  20. # mas dentro de uma f-string tem que ser a própria variável
  21. print(f'{"1º PERÍODO":<{tamanho}}{"2º PERÍODO":<{tamanho}}{"3º PERÍODO":<{tamanho}}{"4º PERÍODO":<{tamanho}}{"5º PERÍODO":<{tamanho}}')
  22.  
  23. for metas in zip_longest(*plan, fillvalue=''):
  24. print(('{:<{size}}' * len(metas)).format(*map(lambda x: formata(x, 2), metas), size=tamanho))
Success #stdin #stdout 0.02s 9200KB
stdin
Standard input is empty
stdout
1º PERÍODO     2º PERÍODO     3º PERÍODO     4º PERÍODO     5º PERÍODO     
1º PERÍODO     2º PERÍODO     3º PERÍODO     4º PERÍODO     5º PERÍODO     
2000.00        2000.00        2000.00        1250.00        1250.00        
2000.00        2000.00        2000.00        1250.00        1250.00        
2000.00        2000.00        1250.00        1250.00        1250.00        
2000.00        2000.00        1250.00        1250.00                       
2000.00        2000.00        1250.00        1250.00                       
2000.00        2000.00        1250.00        1250.00                       
               2000.00        1250.00        1250.00