Hi, need some help with home work i have.
need to wright a code of a function that sum of invoice series
def SumIN(a1 ,an ,n )
the demands are : if n=0 ,print that the sum is 0
and if n=1, print that the sum is 1
and else, print π(π1+ππ)/2 .
a1 - first number
an - last numer
n - the number of the series
that what i did so far :
def question1(a1, an, n):
for i in range(a1,n+1):
if n == 0:
print('the sum is 0')
if n == 1:
print('the sum is', a1)
else:
print("The sum is :" ,n*(a1+an)/2)
It gives me an error onto this line
for i in range(a1, n+1):
The argument may be an int eger or a floating point number.
If u have n+1 in your argument the code will fail
Iβve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
See this post to find the backtick on your keyboard. The βpreformatted textβ tool in the editor (</>) will also add backticks around text.
indentation is really important in python, the second if statement is reached only if the first one is executed (you have put the second if statement inside the first)