Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help! Function doesn't run
#6
Agree there are better ways, such as that suggested by ndc85430. However, following the method you created -
You don't need a maximum range as outer loop. Just test to see if the len(primes) is 1000 and quit when it is.
You also need to check if the mod of each prime is 0, not just 2,3,5,7. Your routine will flag 11*13 as prime which it isn't.
Don't print from the function. As discussed in other threads, a function should return a result. The only time a function should print is if that is actually the purpose of the function (it is a function that prints data in a particular format, for example).
To make this more useful, make the function take an argument that specifies which prime. Then call it on 1000 and it gives the 1000th prime.
Reply


Messages In This Thread
Help! Function doesn't run - by bwdu - Jul-07-2020, 11:11 AM
RE: Help! Function doesn't run - by TomToad - Jul-07-2020, 11:24 AM
RE: Help! Function doesn't run - by jefsummers - Jul-07-2020, 11:36 AM
RE: Help! Function doesn't run - by bwdu - Jul-09-2020, 05:48 PM
RE: Help! Function doesn't run - by ndc85430 - Jul-09-2020, 05:57 PM
RE: Help! Function doesn't run - by jefsummers - Jul-10-2020, 01:50 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  string function doesn't work in script ClockPillow 3 2,451 Jul-13-2021, 02:47 PM
Last Post: deanhystad
Star NameError – function doesn't recognize imported modules Sir 4 3,584 Dec-01-2020, 06:36 AM
Last Post: Sir
  len() function, numbers doesn't work with Geany Editor Penguin827 3 3,044 May-08-2020, 04:08 AM
Last Post: buran
  why my function doesn't work cimerio 4 2,947 Jan-20-2020, 08:11 PM
Last Post: cimerio
  Doesn't work function pyautogui.typewrite() aliyevmiras 1 4,858 Dec-22-2019, 11:35 AM
Last Post: aliyevmiras
  len() function doesn't work with Geany Editor hudabaig 2 3,630 Jun-01-2018, 11:20 PM
Last Post: wavic

Forum Jump:

User Panel Messages

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