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
  Prime number detector Mark17 5 874 Nov-27-2023, 12:53 PM
Last Post: deanhystad
  Problem with "Number List" problem on HackerRank Pnerd 5 2,160 Apr-12-2022, 12:25 AM
Last Post: Pnerd
  Pairs of multiplied prime number--->N Frankduc 13 3,618 Jan-16-2022, 01:52 PM
Last Post: Frankduc
  number accuracy problem? roym 5 1,885 Dec-24-2021, 07:57 AM
Last Post: roym
  Problem : Count the number of Duplicates NeedHelpPython 3 4,436 Dec-16-2021, 06:53 AM
Last Post: Gribouillis
  Script stop work after 3 actioins - PLEASE WHERE IS THE PROBLEM? rondon442 0 1,583 Sep-27-2021, 05:40 PM
Last Post: rondon442
  Problem executing a script on a remote host tester_V 3 2,516 Sep-26-2021, 04:25 AM
Last Post: tester_V
  problem with sphinx and file directory in script kiyoshi7 0 2,311 Mar-11-2021, 03:52 PM
Last Post: kiyoshi7
  P3, openpyxl, csv to xlsx, cell is not number, problem with colorize genderbee 1 2,195 Sep-29-2020, 03:20 PM
Last Post: Larz60+
  problem about slope in python script for bitcoin trading fisher_garry 1 2,533 Sep-02-2020, 01:39 PM
Last Post: fisher_garry

Forum Jump:

User Panel Messages

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