Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Prime code not working?
#1
Hi

I'm new to Python and new to this forum, but hope that someone can help with this question?

I've got some code which lists Prime numbers between 1 and 100.

However, it's not working!

Does anyone know what the error is?

def isprime(n):
    if n <= 1:
        return False
    for x in range(2, n):
        if n % x == 0:
            return False
    else:
        return True

def list_primes():
    for n in range(100):
        if isprime(n):
            print(n, end=' ', flush=True)
    print ()

list_primes
Thanks in advance.
Reply
#2
Line 16 should be
list_primes()
Result is then
Output:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
Nice job!
Reply
#3
Awesome!

That worked!

Thanks ever so much, jefsummers!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  code isnt working. nezercat33 1 582 Mar-14-2025, 03:45 AM
Last Post: deanhystad
  Improve Prime Pairs Code jzakiya 7 1,439 Mar-09-2025, 08:19 PM
Last Post: jzakiya
  Simple code not working properly tmv 2 475 Feb-28-2025, 09:27 PM
Last Post: deanhystad
  I'm new to Python - can someone help with this code as it is not working? lminc123 1 484 Feb-13-2025, 06:13 PM
Last Post: lminc123
  my code is not working erTurko 1 628 Nov-11-2024, 08:43 AM
Last Post: buran
  New to Python - Not sure why this code isn't working - Any help appreciated TheGreatNinx 4 2,274 Jul-22-2023, 10:21 PM
Last Post: Pedroski55
  code not working when executed from flask app ThomasDC 1 3,038 Jul-18-2023, 07:16 AM
Last Post: ThomasDC
  I am new to python and Could someone please explain how this below code is working? kartheekdas 2 1,759 Dec-19-2022, 05:24 PM
Last Post: kartheekdas
Exclamation My code is not working as I expected and I don't know why! Marinho 4 2,157 Oct-13-2022, 08:09 PM
Last Post: deanhystad
  My Code isn't working... End3r 4 3,263 Mar-21-2022, 10:12 AM
Last Post: End3r

Forum Jump:

User Panel Messages

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