Python Forum
prime numbers generator is generating non prime numbers?
Thread Rating:
  • 2 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
prime numbers generator is generating non prime numbers?
#1
Hey guys. I wanted to create a prime numbers generator. This is how the program looks at the moment:
from decimal import *
PRIMES = [2]
p = 3
n = 2 
x = int(input("Until which number do you want to know the primes?"))
while True:
    if p/n == int(p/n) and p/n != 1.0:
        p = p+1
    if p/n != int(p/n):
        n = n+1
    if p/n == 1:
        PRIMES.append(p)
        p = p+1
        n = 2
    if p > x:
        break
print(PRIMES)
the program works okay, but it says, that some numbers are primes, which are just no primes. (For example 27)
So I would love it, if you could have a look for the program and tell me what mistake I have made.

Greets, ixaM

PS: You may have found some vocabulary or grammaticly mistakes in the text. Keep them with u :) I am not from an englishspeaking country, so yeah, my english is kinda bad. :(
Reply


Messages In This Thread
prime numbers generator is generating non prime numbers? - by ixaM - Dec-18-2016, 12:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I calculate a ratio from 2 numbers and return an equivalent list of about 1000 Pleiades 8 15,724 Jan-05-2024, 08:30 PM
Last Post: sgrey
  random numbers, randint janeik 2 578 Nov-27-2023, 05:17 PM
Last Post: janeik
  Prime number detector Mark17 5 821 Nov-27-2023, 12:53 PM
Last Post: deanhystad
  Advancing Page Numbers knight2000 4 1,008 May-24-2023, 09:14 AM
Last Post: knight2000
  Pulling Specifics Words/Numbers from String bigpapa 2 778 May-01-2023, 07:22 PM
Last Post: bigpapa
  How do I check if the first X characters of a string are numbers? FirstBornAlbratross 6 1,559 Apr-12-2023, 10:39 AM
Last Post: jefsummers
  find random numbers that are = to the first 2 number of a list. Frankduc 23 3,261 Apr-05-2023, 07:36 PM
Last Post: Frankduc
  prime numbers with iterator and generator cametan_001 8 1,878 Dec-17-2022, 02:41 PM
Last Post: cametan_001
  List of random numbers astral_travel 17 2,725 Dec-02-2022, 10:37 PM
Last Post: deanhystad
  Remove numbers from a list menator01 4 1,355 Nov-13-2022, 01:27 AM
Last Post: menator01

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020