15,921,276 members
See more:
Python
```n1 = 1
n2 = 2
sum = 0
for i in range(1,4000000):
nth = n1 + n2
n1 = n2
n2 = nth
if n1%2 == 0:
sum += n1
elif n2%2 == 0:
sum += n2
print("the even terms sum is",sum)```

this is my approach. I use pycharm but in pycharm the run window prints nothing.I used an online ide and I was getting this:
"Time Limit Exceeded"

I am a beginner so please explain it in a little detail

What I have tried:

```n1 = 1
n2 = 2
sum = 0
for i in range(1,4000000):
nth = n1 + n2
n1 = n2
n2 = nth
if n1%2 == 0:
sum += n1
elif n2%2 == 0:
sum += n2
print("the even terms sum is",sum)```
Posted
Updated 2-Jul-19 10:05am

## Solution 3

The steps you want to take are:
1. move for loop into a function that takes min and max loop values
2. return the sum
3. call the function in an outer loop
4. each time the outer loop runs, print the sum value so you can see process running (with output) even though it will take a long time for the entire program to run.

I'm no Python wiz and this is untested code, but it'll look something like the following:
Loop will run 1-10, 11-20, 21-30, etc. to max (1000)
Python
```loopMultiplier = 0;
localSum = 0;
// this is the outer loop that calls the function doFib() multiple times
// each time thru the outer loop you will get a print so you can see it running
for x in range (1, 1000)
localSum += doFib((loopMultiplier *x) +1, loopMultiplier * x)
loopMultiplier += 10
print("the even terms sum is ",localSum)

def doFib(minVal, maxVal) :
n1 = 1
n2 = 2
sum = 0
for i in range(minVal,maxVal):
nth = n1 + n2
n1 = n2
n2 = nth
if n1%2 == 0:
sum += n1
elif n2%2 == 0:
sum += n2
return sum```

## Solution 1

It's doesn't do any printing until the for loop is done.
The print statement only runs after the for loop has iterated through 4 million times.

You are getting the
`"Time Limit Exceeded"`
message because it's taking a long time.

Have you tried a smaller number in the for loop to see if you get something?

Try:
Python
`for i in range(1,200):`