I'm trying to write a program to print the first 100 Fibonacci numbers. This is my code:
def main():
print("The first 100 Fibonacci numbers are: ")
fibonacciList = (0,0,1)
loop = False
while not loop:
listLength = len(fibonacciList)
newFibonacci = fibonacciList[-1] + fibonacciList[-2]
fibonacciList = newFibonacci + fibonacciList
if (listLength > 103):
loop = true
print(fibonacciList)
main()
When I run it I get the error below referring to the fibonacciList = newFibonacci + fibonacciList line:
TypeError: unsupported operand type(s) for +: 'int' and 'tuple'
I don't understand what's wrong.
P.S.: The two zeroes in the Fibonacci list are there to prevent a few other errors I got earlier.
fibonacciList = newFibonacci + fibonacciList, you are performing+overnewFibonacciwhich holdsintvalue andfibonacciListwhich is a tuplefibonacciList = (*fibonacciList, newFibonacci)might be closer to what you are looking for