Create a function addNumbers(x) that takes a number as an argument and adds all the integers between 1 and the number (inclusive) and returns the total number.
Answers
Answered by
0
Answer is in the attachment
Attachments:
Answered by
0
def addNumbers(integer):
number = 0
for i in range(1, integer+1):
number += i
return number
a function addNumbers(x) that takes a number as an argument and adds all the integers between 1 and the number (inclusive) and returns the total number.
- define the function with a single argument
- define a varible under the function (mind indentation) to store added value
- we use for loop from range 1 to value of argument + 1 as we must add the number itself
- then return the the value which comes out after summation
Similar questions
Math,
5 months ago
Math,
5 months ago
Computer Science,
11 months ago
Computer Science,
11 months ago
Math,
1 year ago
Physics,
1 year ago
Math,
1 year ago