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]
3 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]3 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
If you look at a white object through a glass of any color, it must appear to remain white.
vodomira [7]
False. It will appear the colour of the glass, but just a bit lighter. It’s like looking through floured water or a balloon
4 0
3 years ago
What is computer hadware​
Alex Ar [27]

Answer: like the monitor or the keyboard

Explanation: it is true i even looked it up and it was true

8 0
2 years ago
The compiler decides which version of a polymorphic method to call at compile time
astra-53 [7]

Answer:

T

Explanation:

Hope it's help.you.

plz Mark me as brinliest

Thank you

8 0
3 years ago
What is a nonimpact printer that creates characters and images with dots by using a drum and toner called?
rusak2 [61]

The answer is Laser Printer.  It is a non impact printer that creates characters and images with dots by using a drum and toner.  The main advantages of laser printers are speed, precision and economy. A laser can move very quickly, and because the laser beam has an unvarying diameter, it can draw more precisely, without spilling any excess ink.

5 0
3 years ago
What effects convert colors in a picture to a wide variety of hues?
nadezda [96]
I believe it's color saturation.
3 0
3 years ago
Other questions:
  • Question 4 of 10
    5·1 answer
  • Seasons Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month a
    14·1 answer
  • A server-side extension ________________. provides its services to the web server in a way that is totally transparent to the cl
    13·1 answer
  • You have successfully compiled the file Hi.java, how do you run the corresponding program from the command line?
    7·1 answer
  • What refers to the protocolâ s ability to ensure that data hasnâ t been modified in any way?
    15·1 answer
  • Why do we have to watch a video to get answers?
    7·2 answers
  • 40 is 20 % percent of what?​
    9·1 answer
  • You want to receive alerts if unusual activity is detected relating to the Web servers deployed in your perimeter network. What
    7·1 answer
  • What is the acronym DOS in full
    15·1 answer
  • You can enter the following things in cells
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!