Advertisement
elizeub

Calculo ano bissexto comentado em python

Jul 22nd, 2021
2,288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.02 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. #  Bissexto.py
  5. #  
  6. #  Copyright 2021 Elizeu Barbosa Abreu <elizeubcorreios@gmail.com>
  7. #  
  8. #  This program is free software; you can redistribute it and/or modify
  9. #  it under the terms of the GNU General Public License as published by
  10. #  the Free Software Foundation; either version 2 of the License, or
  11. #  (at your option) any later version.
  12. #  
  13. #  This program is distributed in the hope that it will be useful,
  14. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. #  GNU General Public License for more details.
  17. #  
  18. #  You should have received a copy of the GNU General Public License
  19. #  along with this program; if not, write to the Free Software
  20. #  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  21. #  MA 02110-1301, USA.
  22. #  
  23. #  
  24.  
  25. # IMPORTAÇÃO DAS BIBLIOTECAS E RECURSOS
  26. from datetime import date
  27. import os
  28. from time import sleep
  29.  
  30. # DEFINIÇÃO DAS CORES USADAS NO PROJETO
  31. class bcolors:
  32.     OK = '\033[92m' #GREEN
  33.     WARNING = '\033[93m' #YELLOW
  34.     FAIL = '\033[91m' #RED
  35.     RESET = '\033[0m' #RESET COLOR
  36.  
  37. # FUNÇÃO PARA LIMPAR A TELA
  38. def cls(): #limpar tela
  39.     os.system('clear')
  40.  
  41. # FUNÇÃO CALCULAR ANO BISSEXTO
  42. def software():
  43.     # INSERÇÃO DOS VALORES
  44.     ano = int(input('\n{}Digite o ano que deseja analizar se é bissexto: {}'.format(bcolors.FAIL, bcolors.RESET)))
  45.     cls()
  46.    
  47.     print('{}{:^45}{}'.format(bcolors.OK, 'ANO BISSEXTO', bcolors.RESET))
  48.     print('\nFOLHEANDO CALENDÁRIO...')
  49.     sleep(2)
  50.     cls()
  51.    
  52.     print('{}{:^45}{}'.format(bcolors.OK, 'ANO BISSEXTO', bcolors.RESET))
  53.     print('\nAGUARDE MAIS UM POUQUINHO...')
  54.     sleep(2)
  55.     cls()
  56.    
  57.     print('{}{:^45}{}'.format(bcolors.OK, 'ANO BISSEXTO', bcolors.RESET))
  58.     print('\nAGORA VAI...')
  59.     sleep(2)
  60.     cls()
  61.    
  62.     print('{}{:^45}{}'.format(bcolors.OK, 'ANO BISSEXTO', bcolors.RESET))
  63.    
  64.     # CONDICIONAL PARA ALGORÍTMO DE CALCULO DE ANO BISSEXTO
  65.     # PARA SER BISSEXTO, O ANO DEVE SER:
  66.     # *DIVISÍVEL POR 4. SENDO ASSIM, A DIVISÃO É EXATA COM O RESTO IGUAL A ZERO; [ano % 4 == 0]
  67.     # *NÃO PODE SER DIVISÍVEL POR 100. COM ISSO, A DIVISÃO NÃO É EXATA, OU SEJA, DEIXA RESTO DIFERENTE DE ZERO; [ano % 100 != 0]
  68.     # *PODE SER QUE SEJA DIVISÍVEL POR 400. CASO SEJA DIVISÍVEL POR 400, A DIVISÃO DEVE SER EXATA, DEIXANDO O RESTO IGUAL A ZERO. [ano % 400 == 0]
  69.     # FONTE: HTTPS://ESCOLAKIDS.UOL.COM.BR/MATEMATICA/CALCULO-DO-ANO-BISSEXTO.HTM
  70.     if ano % 4 == 0 and ano % 100 != 0 or ano % 400 == 0:
  71.         print('\nO ano {} é {}BISSEXTO{}!'.format(ano, bcolors.OK, bcolors.RESET))
  72.     else:
  73.         print('\nO ano {} {}NÃO É BISSEXTO{}!'.format(ano, bcolors.FAIL, bcolors.RESET))
  74.    
  75.     sleep(5)
  76.     cls()
  77.    
  78.     print('{}{:^45}{}'.format(bcolors.OK, 'ANO BISSEXTO', bcolors.RESET))
  79.     print('\nPREPARANDO NOVA ANÁLISE...')
  80.     sleep(2)
  81.     cls()
  82.  
  83. c = True
  84. while c:
  85.     print('{}{:^45}{}'.format(bcolors.OK, 'ANO BISSEXTO', bcolors.RESET))
  86.     print('\n{}Este aplicativo verifica se um ano é bissexto ou não!!!{}'.format(bcolors.WARNING, bcolors.RESET))
  87.     software()
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement