+ 1

¿Cómo saber si un número es primo en Python?

Debo hacer un código que me diga si un número es primo en Python con funciones. Sin while. Por favor ayuda

17th Nov 2021, 9:07 PM
David Aldana
8 Respostas
18th Nov 2021, 6:33 AM
Jairo Soto
Jairo Soto - avatar
+ 1
You could use a for- instead of a while-loop
17th Nov 2021, 9:27 PM
Lisa
Lisa - avatar
+ 1
You can check It with a condition: if i%2 == 0: print("It is multiplicable to two") else: print("Isn't multiplicable to two") Or for more especific: for i in range(0,num): if i%2 == 0: print("It is multiplicable to two") else: print("Isn't multiplicable to two")
18th Nov 2021, 5:40 AM
Katdotbrush
Katdotbrush - avatar
+ 1
Jairo Soto I think not, because the i is increasing and while It, We are moduling him by 2 So, Just think: 1/2 = 1 (It is not multiplicaple) 2/2 = 0 (It is multiplicaple) ... It is just my logic 😅
18th Nov 2021, 6:18 AM
Katdotbrush
Katdotbrush - avatar
+ 1
Jairo Soto Yes, but in this code, you canal only see a number (It is helpful sometimes) but you cannot define num's value by yourself This is my attempt: https://code.sololearn.com/cXwfg50FOA07/?ref=app
18th Nov 2021, 9:22 AM
Katdotbrush
Katdotbrush - avatar
0
Puesto que tiende más a un problema matemático, supongo que mediante algoritmos de factorización.
17th Nov 2021, 11:26 PM
Augusto Hernandez
Augusto Hernandez - avatar
0
Usa el bucle for y el module "%"
18th Nov 2021, 3:00 AM
Jairo Soto
Jairo Soto - avatar
0
Cat do Chrome I think that "if num % i == 0" is better for this case. what do you think?
18th Nov 2021, 6:03 AM
Jairo Soto
Jairo Soto - avatar