97.2% of all problems people have with Python involves incorrect indentation :-) In your original question, your indentation was incorrect and you need to indent it properly:
def Gradiente(grado):
suma = 0
for i in range(porcent):
x1 = entrenamiento[i][0]
x2 = entrenamiento[i][1]
y = entrenamiento[i][2]
h = 1 / (1 + math.exp(-(t0 + t1 * x1 + x2))) # <-- fix
if grado == 1: # <-- style
suma = suma + (h - y)
elif grado == 2: # <-- style
suma = suma + (h - y) * x1
return suma / porcent
However, you've since made it clear that was a typo on your part when entering the question in which case it'll simply be the missing close-parenthesis on that large mathematical formula (which is also fixed in my code above).
One other change made is the removal of superfluous punctuation from the if statements. People who use them tend to come from a C (or similar language) background where they're necessary. Using them in Python usually just clutters the code unnecessarily.
)for this expression:(1 + math.exp(-(t0 + t1 * x1 + x2))def Gradiente(grado):