AoJol
AoJol

Reputation: 17

Iterating an equation

o_i = o_f(l, 1, f_1)
print(o_i)
o_i = o_f(l, o_i, f_1)
print(o_i)
o_i = o_f(l, o_i, f_1)
print(o_i)
o_i = o_f(l, o_i, f_1)
print(o_i)
o_i = o_f(l, o_i, f_1)
print(o_i)

I have tried

while (f_1 == 10):
    o_i = o_f(l, o_i, f_1)
    print(o_f)

among other codes. Is there a way to create a loop for this series without having to keep on typing or copying and pasting for a long time? I have been trying to use a conventional (for or while) loop to address the issue, but I do not know how to use any of them to actually iterate a set of equations that does not have an unordered/ordered list as a variable. Also, is there a way to retain the solutions as a one dimensional array?

Upvotes: 0

Views: 169

Answers (1)

Random Davis
Random Davis

Reputation: 6857

Here it is with a loop, and a 1D list storing the results:

o_i = 1  # initial value
num_loops = 10  # or however many loop iterations you want
results = []  # the list that stores the results
for _ in range(num_loops):
    o_i = o_f(l, o_i, f_1)
    results.append(o_i)
    print(o_i)

Upvotes: 1

Related Questions