Python Forum
Python Code Help Please
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Code Help Please
#1
Trying to code a python script to list the prime numbers up to 100. Have to start the code with "Counter=2;" and "while Counter<100"
[Image: scripting.png]
[Image: scripting1.png]
counter = 2;
number = 0
while counter < 100:
if isPrime ( number ):
count +=1
#zfill - zero fill, will with zeros
print ({0}1}) .format( str( count ).zfill(3),number)
number +=1

def isPrime( number ):

result=True

for i in range (2, number):

if number %i==0:
result=False
break
if number <=1:
result=False
Reply
#2
You've posted the details of the assignment.

You've posted an image of the code.

You've posted the code itself as just text but not inside python tags, so it is not formatted correctly.

You have not said what your problem is, what help you need, or what error you are getting.

Probably best to define isPrime() before you try to use it.

You have a while loop using counter, but do not increment counter. You have incremented count though.
What's wrong with a for loop anyway?

You never return a value from isPrime().

You only increment the number you are checking IF the previous number was a prime.
I am trying to help you, really, even if it doesn't always seem that way
Reply


Forum Jump:

User Panel Messages

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