Computer Science, asked by rudramukherjee122, 13 days ago

Create a function which accepts an integer as parameter and return sum of its digits. Create another function to input 10 integers and find the sum of the digits of each number.​

Answers

Answered by Equestriadash
4

Function to accept an integer and return the sum of its digits:

def sum_digits(n):

   s = 0

   for i in str(n):

       s = s + int(i)

   return s

Function to input 10 integers and find the sum of the digits of each number:

def sum_digits_10():

   l = list()

   for i in range(10):

       n = int(input("Enter a number: "))

       l.append(n)

   for i in l:

       s = 0

       for j in str(i):

           s = s + int(j)

       print(s)

sum_digits_10()

There are mainly two types of functions.

  • In-built functions
  • User-defined functions

In-built functions are functions that are already existing in the system and can be directly used whenever.

User-defined functions are functions created while typing out a program.

In Python, def is used to create user-defined functions.

Similar questions