I\'m trying to make a list of prime numbers.
primes = []
num=int
for num in range (2,100):
for x in range (2, num):
if (num % x) == 0:
Your code executes and finishes, but it does not compute a list of prime numbers because it contains an error:
When you test each num
to see if it's prime, you can test all possible divisors (as you try to do) and quit if you find a single divisor. If no divisor has been found when you've tested them all, only then add your number to the list
also, the line num=int
is not needed
primes = []
for num in range (2,100):
is_prime=True
for x in range (2, num):
if (num % x) == 0:
is_prime=False
break
if is_prime:
primes.append(num)
print(primes)
input()
The logic in your if-else is incorrect.
If you get a "clean modulo" in your if block, what do you want to happen? Hint: not pass
.
Second, when do you want to append to your prime list?
Not being too specific here as we shouldn't be doing this H/W assignment for you. :)