0

Following is my code:

   class MyClass:
        "This is my second class"
        a=["1224","2334","3445"]
        b=int(input("Enter the PIN number"))
        entries={1224:"X",2334:"Y",3445:"Z"}
        def check(self,int):
                    che=False
                    for c in range(0,3):
                            if (m.b==int(m.a[c])):
                                che=True
                                break
                            else:
                                che=False
                    print(che)               
        def func(int):
                    print('Hello',entries[b])
    m=MyClass()
    m.check(m.b)

Whenever I try to convert String to integer from inside a method I get the TypeError:

Enter the PIN number1224
   Traceback (most recent call last):
  File "MyClass.py", line 18, in <module>
          m.check(m.b)
  File "MyClass.py", line 9, in check
         if (m.b==int(m.a[c])):
TypeError: 'int' object is not callable
2
  • Please add full traceback. Commented Jul 10, 2017 at 16:07
  • One recommendation. In your check method do` self.b` and self.a rather than m.b and m.a as this will allow any name for the class Commented Jul 10, 2017 at 16:08

1 Answer 1

1

Couple things.

  1. I was unable to reproduce your error exactly however I didn't get the correct output, see part 2 for how to get proper output
  2. Why do you want to convert there input into an integer, seeing as currently your list has strings so you want to keep your input as a string.
  3. Just generally in your check method make it self.a and self.b as that means that the class can be named whatever, whereas currently it can cause issues if your class isn't named m

Edit: Also in your for loop, in the first if statement add a break after setting che to true or else it will keep running the for loop and might set che back to false after making it true

Sign up to request clarification or add additional context in comments.

Comments

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.