Lesson 14: Odd, even and prime numbers with modulo

posted Mar 22, 2019, 7:56 AM by Attila Lengyel
import random as r

number = r.randint(0,1000)

if number % 2 == 0:
print(number, "is an even number")
else:
print(number, "is odd number")

#list up prime numbers
prime = [2,3,5,7,11]
while len(prime) < 1000:
nextnum = prime[len(prime) - 1]
stop = False

while stop == False:
nextnum += 1
isPrime = True
for i in prime:
if nextnum % i == 0:
isPrime = False
break
if isPrime:
prime.append(nextnum)
stop = True
print(prime)

Comments