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