I want to create f(n) for Sn = n(n+1)/2. Does this make sense? I feel like a nerd!
Here's what I wrote:
def f(x):
sum=n(n+1)/2
print(sum)
On
You could do something like this
def f(n):
sum=(n*(n+1))/2
return sum
Note that: - return should replace print in functions. Nonetheless, return should be the last thing your function does. Anything after return will yield an error.
Now, you can call your function and send input to it as follows:
print(f(5)) #eg. 5
A few issues with your code:
nis an integer number and therefore also the sum.sumas a variable name, as it makes the built-in functionsum()inaccessible.Instead of
you need to write
and then do something like
print(f(100)).