I'm a physics student and am very, very new to python, and I am having problems with the third Euler problem.

Instead of making a program to find the largest prime factor of the huge number in the problem, I tried generalizing it so that my program takes an input and prints the largest prime factor of that input.

I created what I thought would give me a correct answer, but when running, it does not respond when i input a value such as 10 or 14, for example.

Since I'm new, my goal was not to write the code in the most ergonomical way, but to just get the right answer. So I'm sorry if the code is messy and longer than it has to be. Can anyone see the problem?

- Code: Select all
`#Project Euler Problem 3`

#What is the largest prime factor of the number 600851475143?

#Goal is to find prime factors of a given number.

#I will try to collect the prime factors in a list.

number = int(input("Enter a number to find its largest prime factor: "))

primefactors = []

prime = 2

num = 3

div = 2

while number >= prime:

#Continues dividing with the prime factor until it is not divisible anymore.

#Adds the prime as a prime factor for each succesful division.

while number % prime == 0:

primefactors.append(prime)

number = int(number / prime)

#Change the value of the prime variable to the next prime integer.

while div <= num:

if div == num:

#num is a prime if the loop cycles through all values of div up to num.

prime = num

break

elif num % div == 0:

#If num is not a prime, add 1 to num and check again.

num += 1

continue

else:

div += 1

continue

largestprimefactor = max(primefactors)

print(largestprimefactor)