1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Oksi-84 [34.3K]
2 years ago
5

Write a recursive method named digitSum that accepts an integer as a parameter and returns the sum of its digits. For example, c

alling digitSum(1729) should return 1 7 2 9, which is 19. If the number is negative, return the negation of the value. For example, calling digitSum(-1729) should return -19.
Computers and Technology
1 answer:
harkovskaia [24]2 years ago
4 0

Answer:

The function in Python is as follows:

def digitSum( n ):

if n == 0:

 return 0

if n>0:

    return (n % 10 + digitSum(int(n / 10)))

else:

    return -1 * (abs(n) % 10 + digitSum(int(abs(n) / 10)))

Explanation:

This defines the method

def digitSum( n ):

This returns 0 if the number is 0

<em> if n == 0: </em>

<em>  return 0 </em>

If the number is greater than 0, this recursively sum up the digits

<em> if n>0: </em>

<em>     return (n % 10 + digitSum(int(n / 10))) </em>

If the number is lesser than 0, this recursively sum up the absolute value of the digits (i.e. the positive equivalent). The result is then negated

<em> else: </em>

<em>     return -1 * (abs(n) % 10 + digitSum(int(abs(n) / 10)))</em>

You might be interested in
Put the following events from computer history in the order they happened:
kykrilka [37]
Show us a picture so we can answer
7 0
2 years ago
4. Explain the term prejudice. What is an example of prejudice as it relates to parenting?
lara [203]
An unfavorable opinion or feeling formed beforehand or without knowledge, thought, or reason.
2.
any preconceived opinion or feeling, either favorable or unfavorable.
3.
unreasonable feelings, opinions, or attitudes, especially of a hostile nature, regarding an ethnic, racial, social, or religious group.
4.
such attitudes considered collectively:
The war against prejudice is never-ending.
5.
damage or injury; detriment:
a law that operated to the prejudice of the majority.
7 0
3 years ago
Once you have a listing of every unique combination of salesperson, product and location, what Excel function would you use to c
andre [41]

Answer:

SUMIFS

Explanation:

As we know that the excel is used to present the data in a very attractive way by applying the formulas, pie charts, functions as a pivot table, goal seeking, macros, etc

In order to determine the total sales for each and every sales person, production and location combination we use the SUMIFS function so that the total of each column could come in an easiest and better way

7 0
3 years ago
Excel - To clear the active cell, you can use the Ribbon, the keyboard, or the mouse.
____ [38]
The answer to your question is true
8 0
3 years ago
The annual percentage rate on a credit card determines _______. Athe amount of interest you are charged on credit card purchases
Ostrovityanka [42]
The answer is (a.) The amount of interest you are charged on credit card purchases

The Annual Percentage Rate or APR on your credit card is determined by the interest you made from your purchases for the whole year. APR includes other fees and additional costs.
8 0
3 years ago
Read 2 more answers
Other questions:
  • A flowchart would be an example of what kind of programming?
    12·1 answer
  • What is the binary answer to the binary number 100 added to the binary number 11?
    14·2 answers
  • What nondestructive testing method requires little or no part preparation, is used to detect surface or near-surface defects in
    7·1 answer
  • Remy’s manager has asked him to change the background color scheme from reds to blues in the standard template the company uses
    15·2 answers
  • If after a run of arc consistency during the backtracking search we end up with the filtered domains of *all* of the not yet ass
    12·1 answer
  • You work on the marketing team for a software company. You do not work closely with the development team; however, you need to k
    8·1 answer
  • You want to make the background of a Web page blue, click _____.
    13·2 answers
  • New Top Level Domains (TLDs) are coordinated by:_______.
    10·1 answer
  • A 9-year old male castrated Westie presents on emergency after being rescued from a house fire. On presentation, the dog has a r
    9·1 answer
  • Computer is an example of​
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!