-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathPrograma 4_30.py
More file actions
27 lines (26 loc) · 831 Bytes
/
Programa 4_30.py
File metadata and controls
27 lines (26 loc) · 831 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# -*- coding: utf-8 -*-
"""
@author: guardati
Solución del problema 4.30
Determina si un número es primo o no.
"""
numero = int(input('\nIngrese un número entero positivo: '))
if numero <= 0:
print('\nError en el dato.')
else:
if numero == 2:
primo = True
else:
primo = False
# Descarta el 1 y todos los pares > 2.
if numero > 2 and numero % 2 != 0:
divisor = 3
limite = numero // 2
while divisor < limite and numero % divisor != 0:
divisor += 2
if divisor >= limite:
primo = True
if primo:
print(f'\nEl número {numero} es un número primo.')
else:
print(f'\nEl número {numero} no es un número primo.')