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

3.5 #9

Open eline13 opened 2 years ago

eline13 commented 2 years ago

35

hi, i am this far in 3.5, but it seems like i do something wrong, what do i miss?

Fraekfyr91 commented 2 years ago

Hi eline13

You should call the exponential function on the natural logarithm, so the function you create in 0.34 on the new function, so use the natural_logaritihm you already made and then switch the places so you don't use the log on the exponent.

Kind regards Lasse

NiccoloGhionzoli commented 2 years ago

This is my solution, but I have some doubts about the end of the code when I should call the nested function...the code works but it returns a strange result at the end...best regards, Niccolò

define the variables

x = 1 k_max = 100

function natural_logarithm

def natural_logarithm(x,k_max): total = 0 k = 0 while k < k_max: my_log = (1/(2k+1)) (((x-1)/(x+1))*(2k+1)) total += my_log k += 1

return total

print(total)
answer_034 = 2 * total
return answer_034

function eulers_e

def eulers_e(x,k): answer_033 = (1 + (x/k))**k return answer_033

nested functions

def exponentiate(func): def with_exp(x, k): e = eulers_e(x, k) value = func(e, k) return value return with_exp

Call the exponentiate function on natural_logarithm and store the result in a new variable called logexp.

Then call logexp(1, 100) and store this value in the variable answer_035

answer_035 = exponentiate(natural_logarithm(1,100))

print(answer_035)

logexp = exponentiate(natural_logarithm(x,k_max)) answer_035 = logexp print(answer_035)