Python Forum
python prime number algorithm
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
python prime number algorithm
#2
I don't see anything wrong with your code, except that it could be more efficient. 9 is not a prime number as it is equal to 3 * 3. The output I get is:
2 is a prime number
3 is a prime number
4 equals 2 * 2
5 is a prime number
6 equals 2 * 3
7 is a prime number
8 equals 2 * 4
9 equals 3 * 3
As indicated below the example in the link, the else belongs to the for loop, NOT to the if statement.
Reply


Messages In This Thread
python prime number algorithm - by zowhair - Dec-20-2017, 04:22 AM
RE: python prime number algorithm - by squenson - Dec-20-2017, 07:21 AM
RE: python prime number algorithm - by buran - Dec-20-2017, 08:05 AM
RE: python prime number algorithm - by zowhair - Dec-20-2017, 06:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Algorithm for extracting comments from Python source code Pavel1982 6 763 Feb-28-2024, 09:52 PM
Last Post: Pavel1982
  Prime number detector Mark17 5 932 Nov-27-2023, 12:53 PM
Last Post: deanhystad
  Rock paper scissors in python with "algorithm" Agat0 23 6,381 Mar-01-2022, 03:20 PM
Last Post: Agat0
  Pairs of multiplied prime number--->N Frankduc 13 3,773 Jan-16-2022, 01:52 PM
Last Post: Frankduc
  Is 2 a prime number? for loop & range fuction in python docs says yes, mine says no. allusernametaken 4 3,019 Nov-17-2019, 02:56 AM
Last Post: allusernametaken
  check if the number is a prime integer atlass218 5 3,056 Sep-26-2019, 07:58 AM
Last Post: atlass218
  Can Python 3.6 program handle Python 2.7 algorithm? Socrates123 2 1,921 May-14-2019, 09:20 PM
Last Post: snippsat
  Creating a program to look for the largest prime number of a number Wikki14 4 4,009 Sep-08-2018, 12:30 AM
Last Post: Skaperen
  python result problem of an iteration algorithm for power allocation Jessica 1 2,748 Sep-07-2018, 08:08 PM
Last Post: micseydel
  Cage filling algorithm - Python bnbehera 3 3,231 Jul-02-2018, 04:55 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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