I have it set so the user enters a max input and then the program figures out which numbers are prime and then prints it all to a file. But at the moment it only prints the closest prime number to the upper input. I need it to print 20 random numbers and put them on a file. Also with print (num)
20 times it can print 20 different outputs, but if I add print (num)
20 times it prints the same number 20 times
import random
#Always start at 2
lower = 2
#Take input from the user
upper = int(input("Enter maximum size for prime number to be: "))
for num in range(lower,upper + 1):
if num > 1:
#Prime numbers are greater than 1
for i in range(2,num):
if (num % i) == 0:
break
#End program if number is 0
#Print results
else:
randomprimes =(num)
primes =(random.choice(randomprimes))
import sys
former, sys.stdout = sys.stdout, open('Prime Number Generator Output.txt', 'w')
print (primes)
results, sys.stdout = sys.stdout, former
results.close()