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
QUESTION 5
Zepler [3.9K]

Answer:

allows users to accomplish tasks such as create text documents.

Explanation:

8 0
2 years ago
In disc brakes, pads are forced against the of a brake disc​
Arturiano [62]

Answer:

Explanation:

It's the surface the brake pads contact. When you step on the brakes, pressurized brake fluid pushes against the pistons inside the caliper, forcing the brake pads against the rotor. As the brake pads press against both sides of the disc, the friction stops the wheel's rotation.

6 0
2 years ago
What is the danger in judging someone according to his or her social networking profile
AfilCa [17]
They could find you and throw hands.
8 0
2 years ago
Select the correct answer. One of the functions of a data warehouse is to change table names to meaningful names. Which name is
Marianna [84]

Answer:

A. weekrep101

Explanation:

hope this worked and notice the update

6 0
2 years ago
Which girl is he baddest 1. Shawty 2.Lisa 3.Ashley
Ainat [17]

Answer:

. . . . . . . S H A W T Y.. . .. . .

3 0
2 years ago
Other questions:
  • Which element of presentation software can you use to add callouts and banners?
    5·2 answers
  • Why would it be beneficial to preview a page before printing?
    8·1 answer
  • What are two advantages of encrypting data stored in the computer system?
    5·1 answer
  • What are lexical errors?<br> and fi(a==b)<br> will it be a lexical error or a syntactical error?
    8·1 answer
  • ANYONE GOOD WITH CODING IN C++
    14·1 answer
  • How do entrepreneurs traditionally use computers? check all of the boxes that apply.​
    13·2 answers
  • Explain mechanical computer ,electromechanical and electronic computer with example<br>​
    11·1 answer
  • What is the impact of VR on Educational Learning rather than games?​
    13·1 answer
  • Does analogue conversation take place in source as transmitter?
    5·2 answers
  • What does mean in computer science
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!