tranformative

Asked

Viewed 38 times

1

def eR(k,x):

    if k<=1:

     return 1
    else:
        return (x**k)/eR(k-1,x)*k

x=int(input("Insira o X:"))

k=int(input("Insira o número de termos:"))

print(eR(k,x))
  • the recursive code I made but iterative cannot because it assigns k= k-1 to make factorial swap the variable of x**k ae a different result

1 answer

1


def eR(k, x):
    result = 1
    for kp in range(2, k + 1):
        result = (x ** kp) / result * kp
    return result

Com while:

def eR(k, x):
    kp = result = 1
    while kp < k:
        kp += 1
        result = (x ** kp) / result * kp
    return result
  • but ta displaying different recursive result

  • @Oops, I already edited the answer, one missing +1

  • you used it for how to do with while or with if it has how to make me an idea

  • @But I put with while in response

  • it worked vlw thanks I understood how you did I’ll do next

Browser other questions tagged

You are not signed in. Login or sign up in order to post.