Reputation: 3
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
Upvotes: 0
Views: 233
Reputation: 989
Couple things.
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 mEdit: 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
Upvotes: 1