I can't seem to make random prime numbers using this code, please can someone help me?
def RandomPrime():
prime = False
while prime == False:
n = random.randint(10000, 100000)
if n % 2 != 0:
for x in range(3, int(n**0.5), 2):
if n % x ==0:
prime = False
else:
prime = True
return n
Correct logic, you are setting
True
whenn % x
! =0
for first time:should be:
Read break and continue Statements, and else Clauses on Loops.
The shorter way of writing equivalent code will be (from @Steve Jesso):