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
Non related to school but im interested,<br><br> Who here actually watches dream smp be honest
Kamila [148]
I did- but I don’t anymore
3 0
2 years ago
Read 2 more answers
1.
natka813 [3]
Its gonna be about 39%.
6 0
3 years ago
The Operating System provides utility software designed to perform specific tasks. What task(s) does it perform? Select all that
viktelen [127]

Answer:

All of the above.

Explanation:

An operating system is a system software pre-installed on a computing device to manage or control software application, computer hardware and user processes.

This ultimately implies that, an operating system acts as an interface or intermediary between the computer end user and the hardware portion of the computer system (computer hardware) in the processing and execution of instructions.

Some examples of an operating system on computers are QNX, Linux, OpenVMS, MacOS, Microsoft windows, IBM, Solaris, VM etc.

Hence, the operating system (OS) provides utility software designed to perform specific tasks. Some of the tasks it performs are;

A. Establishing an Internet connection.

B. Coordinating tasks between programs.

C. Configuring peripheral devices.

D. Monitoring security.

7 0
2 years ago
Write a function that takes a string like 'one five two' and returns the corresponding integer (in this case, 152). A function j
Lelu [443]

Answer:

see explaination

Explanation:

def words2number(s):

words = s.split()

numbers = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']

result = ""

for word in words:

if word in numbers:

result += str(numbers.index(word))

return result

4 0
3 years ago
Read 2 more answers
Sites like Zillow get input about house prices from a database and provide nice summaries for readers. Write a program with two
Sonja [21]

Answer:

integer currentPrice

integer lastMonthPrice

integer changeLastMonth

float mortagage

//Reading input

currentPrice = Get next input

lastMonthPrice = Get next input

//Calculating price change

changeLastMonth = currentPrice - lastMonthPrice

//Calculating mortagage

mortagage = (currentPrice * 0.045) / 12

//Printing output

Put "This house is $" to output

Put currentPrice to output

Put "\nThe change is $" to output

Put changeLastMonth to output

Put " since last month." to output

Put "\nThe estimated monthly mortgage is $" to output

Put mortagage to output

7 0
3 years ago
Read 2 more answers
Other questions:
  • A Game Object must have a Transform<br><br> True<br><br> False
    5·1 answer
  • Who was eqvtime tayaishvili?​
    13·2 answers
  • How would you display all your photographic work in your résumé, if you have a large volume of work?
    10·1 answer
  • 1. Define a C++ function with the name evaluateBook. The function receives as one argument the name of the file to be processed
    13·1 answer
  • What disese is sue suffering from
    15·2 answers
  • ---------------is a systematic review of a person’swork and achievements over a recent period, usually leading toplans for the f
    11·1 answer
  • True or False The two types of general construction projects are residential for homes or dwellings and commercial for a commerc
    7·1 answer
  • What are two advantages of a pay-for-use online conferencing service compared to a free service? (Choose two)
    5·1 answer
  • I came here for a answer so why did i get a pep talk
    7·2 answers
  • Class ____________ allow you to create one version of a class, without having to replicate code to handle multiple data types.
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!