Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Prime number Script Problem
#1
I was creating a script to find prime numbers, I finally figured out how to do it without errors, and nothing printed. Though clearly in the function it says to print the number when it finds it. Can anyone help with this problem?

wrong = 0
primelist = [2]
check = 0
number = 3
def PrimeFinder():
   global check
   global number 
   global wrong
   for i in primelist:
       if number % i == 0 or number % 2 == 0:
           check += 1
           wrong += 1
           if check == len(primelist):
               number +=1
               check = 0
               wrong = 0
               PrimeFinder()
       else:
           check += 1
           if check == len(primelist) and wrong == 0:
               primelist.append(number)
               number = number + 1
               check = 0
               wrong = 0
               print(number)
               PrimeFinder()
           elif len(primelist):
               number += 1
               check = 0
               wrong = 0
               PrimeFinder()
       
Reply
#2
you never call the PrimeFinder function

add at bottom of script
if __name__ == '__main__:
   PrimeFinder()
Reply
#3
I just ran it -- lot's of issues!
you can see how others do it: https://stackoverflow.com/questions/1570...me-numbers
Reply
#4
Ok now I would like to know how to hide the messages saying where the function is stored so it just shows the numbers
Reply
#5
You don't hide them, it's an issue you can only recurse so many times before you run out of heap (stack) space
This applies to most languages unless they have expandable heap.
Even then, eventually you will run out of memory.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Script problem - Illegal access to removed OSM object MarcPolo72 0 893 Jun-23-2024, 04:26 PM
Last Post: MarcPolo72
Music Python Script Repeating Number When Saving Facebook Photos ThuanyPK 2 992 May-13-2024, 10:59 PM
Last Post: ebn852_pan
  Prime number detector Mark17 5 2,178 Nov-27-2023, 12:53 PM
Last Post: deanhystad
  Problem with "Number List" problem on HackerRank Pnerd 5 3,456 Apr-12-2022, 12:25 AM
Last Post: Pnerd
  Pairs of multiplied prime number--->N Frankduc 13 5,859 Jan-16-2022, 01:52 PM
Last Post: Frankduc
  number accuracy problem? roym 5 2,969 Dec-24-2021, 07:57 AM
Last Post: roym
  Problem : Count the number of Duplicates NeedHelpPython 3 7,000 Dec-16-2021, 06:53 AM
Last Post: Gribouillis
  Script stop work after 3 actioins - PLEASE WHERE IS THE PROBLEM? rondon442 0 1,982 Sep-27-2021, 05:40 PM
Last Post: rondon442
  Problem executing a script on a remote host tester_V 3 3,738 Sep-26-2021, 04:25 AM
Last Post: tester_V
  problem with sphinx and file directory in script kiyoshi7 0 2,883 Mar-11-2021, 03:52 PM
Last Post: kiyoshi7

Forum Jump:

User Panel Messages

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