Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #
- # NumerosPrimos.py
- #
- # Copyright 2021 Elizeu Barbosa Abreu <elizeubcorreios@gmail.com>
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- # MA 02110-1301, USA.
- #
- #
- import os
- from time import sleep
- class cor:
- vermelho = '\033[91m'
- verde = '\033[92m'
- inversa = '\033[7m'
- fim = '\033[m'
- def cls():
- os.system('clear')
- count = 0
- # PARA SER PRIMO O NÚMERO PODE SER DIVISÍVEL APENAS POR ELE MESMO OU POR 1.
- # USEI UM CONTADOR QUE CONTA TODAS AS VEZES QUE O NUMERO SENDO DIVIDIDO PELOS SEUS
- # ANTECESSORES RETORNA TRUE. SEI QUE ESTE NÃO É O MÉTODO MAS RÁPIDO MAS FOI A MANEIRA ENCONTRADA
- def primo(count, numero):
- for n in range(numero, 0, -1):
- if numero % n == 0:
- count += 1
- if count == 2:
- print('\n{}{} É UM NÚMERO PRIMO...{}'.format(cor.verde, numero, cor.fim ))
- else:
- print('\n{}{} NÃO É UM NÚMERO PRIMO...{}'.format(cor.vermelho, numero, cor.fim))
- def main():
- cls()
- print('{}{:^45}{}'.format(cor.inversa, 'CALCULADORA DE NÚMEROS PRIMOS', cor.fim))
- print('''
- ESTE ALGORITMO DESCOBRE SE UM NÚMERO DIGITADO É PRIMO!!!
- CUIDADO! O CÁLCULO DE NÚMEROS PRIMOS DE VÁRIOS DÍGITOS EXIGE BASTANTE MEMÓRIA...
- SEJA PACIENTE AO DIGITAR NÚMEROS MAIORES. VÁRIOS CÁLCULOS ESTÃO SENDO REALIZADOS!!!!
- * Para sair pressione [CTRL+C] a qualquer momento!!!
- ''')
- x = str(input('Digite um número inteiro para analisar: '))
- # ANÁLISE SE O NÚMERO DIGITADO É NUMÉRICO
- if x.isnumeric() == False:
- print('\n{}ENTRADA INVÁLIDA... VOCÊ NÃO DIGITOU UM VALOR NUMÉRICO!!!!{}'.format(cor.vermelho, cor.fim))
- sleep(3)
- main()
- else:
- numero = int(x)
- primo(count, numero)
- sleep(7)
- while True:
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement