Ask coding questions

← Back to all posts
3
Primary numbers in pyton
georgegerdes (4)

How do I calculat primary numbs in python? I don't know how to, and i want to learn. Sorry that my language is bed, but i am yung

Answered by enigma_dev (83) [earned 5 cycles]
View Answer
Commentshotnewtop
4
enigma_dev (83)

Hey Georg! This is a program I wrote for calculating primary numbers in python!

# Python program to check if the input number is prime or not

num = 407

# take input from the user
# num = int(input("Enter a number: "))

# prime numbers are greater than 1
if num > 1:
   # check for factors
   for i in range(2,num):
       if (num % i) == 0:
           print(num,"is not a prime number")
           print(i,"times",num//i,"is",num)
           break
   else:
       print(num,"is a prime number")
       
# if input number is less than
# or equal to 1, it is not prime
else:
   print(num,"is not a prime number")

Also, you should poke around in repl.it more! i see you having not a single repl!

1
georgegerdes (4)

@enigma_dev thank ypo so much, i will tets it later!

1
heyitsmarcus (280)

@enigma_dev I agree! Use repl.it to its full extent =]

2
heyitsmarcus (280)

Hey George, here is an article that breaks down several different ways to calculate prime numbers in Python. https://hackernoon.com/prime-numbers-using-python-824ff4b3ea19