##### Unexpected result in simple prime number example
 Unexpected result in simple prime number example jackhj Unladen Swallow Posts: 4 Threads: 3 Joined: Apr 2018 Reputation: Apr-19-2018, 09:06 PM [python code]Numberofprimes = 25 Numberofprimesperline = 5 count = 0 number = 2 while(count < Numberofprimes): isPrime = True for i in range(2,int(number / 2)): if number % i == 0: isPrime = False break if isPrime: count = count + 1 print(count,number) number = number + 1 '[python code] Works fine except it says 4 is prime number which it isn't also how would you print 5 numbers on a line and then go to next line Reply woooee Minister of Silly Walks Posts: 474 Threads: 0 Joined: Feb 2018 Reputation: Apr-19-2018, 09:12 PM So some simple debugging. Print for i in range(2,int(number / 2)) Reply jackhj Unladen Swallow Posts: 4 Threads: 3 Joined: Apr 2018 Reputation: Apr-20-2018, 01:48 AM Solved Problem by for i in range(2,int(1 + number/2)) Indentation was off in original Reply

 Possibly Related Threads… Thread Author Replies Views Last Post Unexpected result linton 4 680 May-02-2020, 01:15 PM Last Post: linton list sum gives unexpected result Nesso 0 538 Feb-04-2020, 08:31 AM Last Post: Nesso Unexpected (?) result with regular expressions guraknugen 2 693 Jan-18-2020, 02:33 PM Last Post: guraknugen Is 2 a prime number? for loop & range fuction in python docs says yes, mine says no. allusernametaken 4 915 Nov-17-2019, 02:56 AM Last Post: allusernametaken check if the number is a prime integer atlass218 5 1,070 Sep-26-2019, 07:58 AM Last Post: atlass218 Unexpected expected type error result MartinMaker 1 1,010 Feb-16-2019, 05:02 PM Last Post: micseydel unexpected sub result after overloading operator jolinchewjb 1 1,028 Jan-24-2019, 08:23 AM Last Post: buran Unexpected result eftimios 1 1,272 Dec-02-2018, 07:39 AM Last Post: Gribouillis Prompting user for number, reading number, squaring it and returning result JHPythonLearner 5 1,459 Sep-13-2018, 04:05 PM Last Post: gruntfutuk Creating a program to look for the largest prime number of a number Wikki14 4 1,992 Sep-08-2018, 12:30 AM Last Post: Skaperen

Forum Jump:

### User Panel Messages

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