You can create a separate method:
for task in self.tasks:
task = randomTask()
...
def randomTask():
while True:
num1 = random.randint(0, 10)
num2 = random.randint(0, 10)
if num1 + num2 <= 10:
break
return "{} + {} =".format(num1, num2)
solved I can’t make this in to a for loop