Jun-10-2020, 03:35 PM
The reason you get two extra numbers in the list is because you are testing x[-3] >. You start with two values in x and j never catches up with the end of the list because each time you test the value of j you add a value to x.
If you want to stop at or before 100, use the DeaD_Eye's test. If you want to stop after the first value >= 100 (kind of what your original code looks like) just use:
If you want to stop at or before 100, use the DeaD_Eye's test. If you want to stop after the first value >= 100 (kind of what your original code looks like) just use:
x = [0, 1] while x[-1] < 100: x.append(x[-1]+x[-2]) print(x)