the nth harmonic number is defined non-recursively as: 1 1/2 1/3 1/4 ... 1/n. come up with a recursive definition and use it to guide you to write a function definition for a double-returned function named harmonic that accepts an int parameter n and recursively calculates and returns the nth harmonic number.

Respuesta :

Return 1/n + harmonic (n-1)

The nth harmonic number can be defined recursively as

H(n) = 1/n + H(n-1)

where H(n) is the nth harmonic number and H(n-1) is the (n-1)th harmonic number.

Using this recursive definition, we can create a function definition for a doubly returned function called "harmonic" that takes an int parameter n and recursively computes and returns the nth harmonic number.

def harmonics (n:

int) -> float:

If n == 1:

return 1

different:

return 1/n + harmonic (n-1)

This function recursively computes the nth harmonic number using the recursive definition above. The result is returned as a float.

Let us take an example, calling the function with n=5 returns the following results:

1 + 1÷2 + 1÷3 + 1÷4 + 1÷5 = 2.28.

Read more about harmonic numbers on brainly.com/question/14307075

#SPJ4