#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    4
    Rep Power
    0

    Help with Simple code


    Hello I m new to python and i cannot figure out why this error keeps coming up for this code:

    Code:
    def fibonacci(number):
        if number <= 1:
            return number
        else:
            return fibonacci(number - 1) + fibonacci(number - 2)
    
    user_input = int(input("Enter number: "))
    fibonacci_of_user_input = fibonacci(input)
    print fibonacci_of_user_input
    the error message is for the return statement in the else. it says

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

    suggestions?
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    Tewksbury, MA
    Posts
    38
    Rep Power
    2
    Originally Posted by CodeHacker1993
    Hello I m new to python and i cannot figure out why this error keeps coming up for this code:

    Code:
    def fibonacci(number):
        if number <= 1:
            return number
        else:
            return fibonacci(number - 1) + fibonacci(number - 2)
    
    user_input = int(input("Enter number: "))
    fibonacci_of_user_input = fibonacci(input)
    print fibonacci_of_user_input
    the error message is for the return statement in the else. it says

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

    suggestions?
    fibonacci_of_user_input = fibonacci(input) <<< Shouldn't that be user_input, not input?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    4
    Rep Power
    0
    OMG! yes! thank you. can't believe i didn't see that.


    I need to be more vigilant next time...

IMN logo majestic logo threadwatch logo seochat tools logo