![]() |
Prime code not working? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Prime code not working? (/thread-24824.html) |
Prime code not working? - NewGuy12 - Mar-06-2020 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_primesThanks in advance. RE: Prime code not working? - jefsummers - Mar-06-2020 Line 16 should be list_primes()Result is then Nice job!
RE: Prime code not working? - NewGuy12 - Mar-07-2020 Awesome! That worked! Thanks ever so much, jefsummers! |