0

I wrote some code for a program that gives me the values of a sequence I defined as a function, f(x), but when I run it a error pops saying 'int' object is not callable". Does anyone know how to solve the problem?

def f(x):
    if x%2==0:
        return x/2
    else:
        return 3*x+1
limite=int(input("parar en: "))   
x=int(input("a1: "))
print(x)
n=1
while n<=limite:
    f=f(x)
    print(f)
    n=n+1
print("fin")

1 Answer 1

5

You're reassigning f within the while loop, to the result of calling f(x), which indeed an integer. So, the second time through the loop, f is an integer rather than a function.

I suspect you simply meant:

x = f(x)
print x
Sign up to request clarification or add additional context in comments.

1 Comment

Javier, also you definitely should to take a look on PEP-0008 document: it defines the coding guidelines, which are respecting by all Python programmers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.