Computer Science, asked by devil7617, 11 months ago

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 Abhis506
0

Answer is in the attachment

Attachments:
Answered by NirmalPandya
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