Prime Factorization Code with Python (Basic)

preview_player
Показать описание
Took me a while to create the code from scratch with my limited skills, but here it is.
#pythoncode #primefactors #promefactorization
# Prime Factorization Engine Code by Ralph Turchiano
from functools import reduce
factors =[]
ff = int(input("Enter Number: "))
dd = 1
gg = ff #Important, Reassign the Variable#
div = 2 #Set divisor to 1 not 2 or will loop forever
while not dd == ff:
gg%div
if gg%div != 0:
div+=1 #Add 1 to the Divisor till the modulus is zero#
elif gg%div ==0:
gg = gg/div #New Number is the quotient#
div=2 #Reset the Divisor#
dd = reduce((lambda a, b: a * b), factors) #Multiplies all the factors in the list until == the input##
else:
print("The Factors of " + str(ff) + " are ",factors )
Рекомендации по теме