isdsucph / isds2022

Introduction to Social Data Science 2022 - a summer school course https://isdsucph.github.io/isds2022/
MIT License
21 stars 23 forks source link

0.3.4 Problem - Code running forever #23

Closed simull closed 2 years ago

simull commented 2 years ago

Update: I did not change the code but this time the code executed and even returned a value. It seems that there was always a process running in the background and no other cell could be executed before I actively pressed the Stop button. You can consider my issue solved.


Dear all,

There are probably several issues with my answer for the 0.3.4 problem. One of it is that it seems to run forever (an asterix appears at the left side of the cell). I thought k = k + 1 would stop it from continuing the loop. Can someone help out?

Best, Simon

def natural_logarithm(x, k_max):
    total_value = 0
    k = 0
    while k <= k_max:
        value = (1/(2*k+1))*((x-1)/(x+1))**(2*k+1)
        total_value = total_value + value
        k = k+1
    return (2 * total_value)

answer_034 = natural_logarithm(2.71, 1)
print(answer_034)