```
import pickle
# Loop to start over (Part 1/2)
done = False
while done == False:
userinput = int(input('Enter a number: '))
# You only have to look to the sqrroot
rootinput = int(userinput**0.5)
# Opens a list with all earlier found primenumbers
primelist = open('C:\Python31\PrimeListMaker\primelist.pkl', 'rb')
plist = pickle.load(primelist)
primelist.close()
i = plist[-1]
# Program that determines if a number is a prime
import isprime
# Checks if sqrroot of userinput is bigger than the last element in plist (list with all stored primenumbers)
if rootinput > i:
i = i + 2
# If rootinput > i and if a number between rootinput is a prime, append this prime to plist
while rootinput > i:
if isprime.isprime(i) == True:
plist.append(i)
print(rootinput - i)
i = i + 2
# Open the primelist file again and save the new plist
primelist = open('C:\Python31\PrimeListMaker\primelist.pkl', 'wb')
pickle.dump(plist, primelist)
primelist.close()
x = 0
factor = []
# while x is smaller than plist elements - check if element is a factor in userinput
while x < len(plist):
if userinput % plist[x] == 0:
z = x
# if plist[x] is factor in userinput check how many times and write result to factor
while userinput % plist[z] == 0:
userinput = userinput/plist[z]
factor.append(plist[z])
x = x + 1
# If userinput is not zero then userinput must now be a factor
if int(userinput) != 1:
factor.append(int(userinput))
# Print all userinputs factors
print(factor)
# Loop to start over (Part 2/2)
yeah = input('Start over? Y/N: ')
if yeah == "N":
done = True
```

Recommended Topics