Invalid syntax in "for item in L" loop
You are missing a closing parenthesis on the line before:
L = primes(int(math.sqrt(perimeter)) #list of primes to divide the perimeter
# ^ ^ ^ ^^
#nesting count 1 2 3 21
See how we don't reach 0 in the "nesting count" below the line?
You're missing a parenthesis:
L = primes(int(math.sqrt(perimeter)))
^
|
this one
This happens to me all the times, you just needed look at the line before.