-
-
Notifications
You must be signed in to change notification settings - Fork 49.6k
Closed as not planned
Labels
Description
#Task is:
Write a (pure) ‹sequence› function that calculates the value of member
⟦aₙ⟧ of the sequence described below, where ‹n› is the first parameter of this function.
The first term of the sequence, ⟦a₀⟧, is given by the parameter ‹initial›,
each other term is then determined by the sum ⟦aⱼ = ∑ᵢ₌₁ᵏ (-1)ⁱ · i · aⱼ₋₁⟧,
where ‹k› is second parameter of the ‹sequence› function.
def sequence(n, k, initial):
for i in range(n+1):
result = 1**k * (-1)**initial * initial * (n-1)
print(result)