I'm new to python and programming in general and I found Project Euler problems a good way to practice python. But my code is pretty slow. It seems to work, didn't wait long enough for the code to print the answer though. Any tips on how to make it faster ? I assume that you don't have to check every single number but that's just a guess any help appreciated.
tri_nums = [1]
divisors = []
temp_divisors =[]
while len(divisors) <= 500:
for x in range(1, tri_nums[-1] + 1):
if tri_nums[-1] % x == 0:
temp_divisors.append(x)
if len(temp_divisors) > len(divisors):
divisors = temp_divisors[:]
temp_divisors.clear()
print("Number: " + str(tri_nums[-1]))
print("Number of divisors: " + str(len(divisors)))
print("List of divisors: " + str(divisors))
tri_nums.append(len(tri_nums) + 1 + tri_nums[-1])