Building prime numbers finder – Python

Prime number finder:

This program checks if the selected number is prime or not, if not Prime program shows all the numbers which is divided

Used: if , else

prime.png
To copy or see all commands you can click on Details button below

 

#!/usr/bin/python
”’
author: Hopeless
task: Prime number finder: write a script that checks if a number is a prime number and devisor_list.
”’

print ‘\nthis program will check if number is prime or not’
num = input (‘enter your number: ‘)
devisor = ”
devisor_list = []

if num == 1:
print ‘prime!’
else:
for i in range(2,num/2+1):
if num%i == 0:
devisor = i;
devisor_list.append(devisor)

if len(devisor_list):
print num, ‘is not a prime number \ndevided by ‘ , devisor_list
else:
print num, ‘is prime number!’

 

Untitled.png

Improve Prime number finder:

This program request lower number and a higher number, the program displays all the prime numbers that are within range

Used: for , if , else , break

primerange.png
To copy or see all commands you can click on Details button below

 

#!/usr/bin/python
”’
author: Hopeless
task: Improved Prime number finder: write a script that finds all prime numbers within a range
(ex: 2,000-8,000),range will be given by user
”’

print ‘\nthis program will check if number is prime or not’
print ‘Please enter a range of numbers first the low number to high’
num = input (‘enter your lower number in range: ‘)
num1 = input (‘enter your upper number in range: ‘)

for numbers in range(num,num1 + 1):
if numbers == 1:
print ‘1 = prime!’
else:
for i in range(2,numbers/2+1):
if (numbers%i) == 0:
break
else:
print (numbers)

 

Untitled1.png

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s