简体   繁体   中英

TypeError: unsupported operand type(s) for -: 'list' and 'int'

I have a the following code:

def fib(n): 
    if n < 1: return 1
    return fib(n-1) + fib(n-2)

Where I would put in an array from 1-10000 as n and it would give me an error. May someone help me point out the problem?

The point of the problem is that you can't pass a list to your function. Your function wants an integer value.

>>> fib(5)
13

As expected. So you should pass just a number (n) to your function to calculate fibonacci of it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM