Python Forum
Trouble interpreting prime number code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trouble interpreting prime number code
#2
range(3, x, 2) returns an iterable beginning with 3 and ending at x. The third argument is the "step" which instructs how to calculate the next value. So, range(3, 12, 2) would include 3, 5, 7, 9, 11.

The "else" is used with the for loop. That block executes once the for loop has completed per the documentation.
Reply


Messages In This Thread
Trouble interpreting prime number code - by ryfoa6 - Mar-20-2020, 05:21 AM
RE: Trouble interpreting prime number code - by stullis - Mar-20-2020, 03:47 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Trying to find the next prime number FirstBornAlbratross 8 4,989 Aug-14-2023, 01:16 PM
Last Post: deanhystad
  Interpreting this code EmBeck87 4 1,637 Apr-10-2023, 12:40 PM
Last Post: EmBeck87
  calculate the 10001st prime number topologh 7 6,411 Oct-05-2020, 07:41 PM
Last Post: deanhystad
  Prime number code ryfoa6 3 2,981 Mar-21-2020, 12:23 AM
Last Post: ryfoa6
  Asking for help in my code for a "Guess the number" game. Domz 5 3,938 Aug-14-2019, 12:35 PM
Last Post: perfringo
  Prime number Python homework mkrisz98 11 5,808 May-10-2019, 05:23 PM
Last Post: mkrisz98
  Help interpreting code schniefen 1 2,130 May-03-2019, 05:23 PM
Last Post: ichabod801
  how to find a next prime number? iamyourfather 2 6,607 Oct-01-2017, 04:21 PM
Last Post: gruntfutuk

Forum Jump:

User Panel Messages

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