Week 3: Assignment 1: Question 2.5

def compute_sum_epsilon(x, epsilon):
    sum = 1
    i = 1
    while True: 
        var = compute_ratio(x, i)
        sum += var
        i += 1
        if var < epsilon :
    return sum
print(compute_sum_epsilon(2, 0.01))

Why does it not run the print statement if run in the same cell?

What’s the error that you’re getting when you’re trying this?

It does not get printed. My doubt is, if the break command moves it out of the cell? Because if I run the print command in next cell, then it gives me result.

No, break can not terminate whole cell, if this was the case then return wouldn’t be executed. And even if we call the function in some other cell, it won’t matter.
Maybe there’s something which we’re missing here… will check and get back to you.

Thanks, even I will try again and see if I get a different result