Open Toromash opened 4 years ago
yeah, i just copy pasted the code directly in. Sorry about that.
If i use the sum-notation, it will say that ´ínt´ object is not iterable. I don´t have a list of numbers, so i don´t see how it can work?
Not the python sum
function, the mathematical one, sorry if that was unclear. You are right that sum
expects an iterable object, so to use it you would first need a list of numbers. Creating the right list of numbers and using sum
is a completely valid solution.
About
I have an issue understanding the description of problem 0.3.3.
The code you pasted doesn't correspond to what the mathematical expression is telling you to calculate. In other words your translation from math to code is wrong - this is why i gave you a link that explains the sigma sum notation. Consider beginning by coding up a far simpler sum (e.g. the sum of integers below some k_max) to get a better intuition for the relation between math and code.
I have an issue understanding the description of problem 0.3.3. I have defined the function and tried to loop it, but there is clearly something wrong with my coding. There is something wrong with the structure, and should i return value twice?
def natural_logarithm(x, k_max): total = 0 for k in range (0, k_max): total += k total = total 2 return (1/2k_max+1)*((x-1)/((x+1))*2k_max+1) answer_033 = natural_logarithm(2.71, 1000)