Since you are new to programming, here is a simple solution (but know that there are substantially more complex solutions that are more efficient). First note that you only need to check divisors up to the square root of num, since if num = a * b then one is less than the square root and one is larger. Secondly you only need to check for prime divisors.
You can generate a list of primes as follows:
import math
import itertools
def primes_generator():
"""Generator for the infinite list of primes."""
primes = [2, 3]
for prime in primes:
yield prime
for c in itertools.count(5, 2):
bound = math.sqrt(c)
for p in primes:
if not (c % p):
break
if p > bound:
primes.append(c)
yield c
break
Now to find the all the prime divisors:
def prime_factorization(number, primes=None):
if not primes:
primes = primes_generator()
factorization = dict()
for p in primes:
count = 0
while not (number % p):
number = number / p
count = count + 1
if count:
factorization[p] = count
if number == 1:
return factorization
The largest prime divisor is just the largest key in the dictionary. These functions should work fine for fairly large inputs. On my machine the following takes 0.06 seconds.
print(max(prime_factorization(1000000001).keys()))