I began coding in Python recently and encountered a problem assigning the value returned by a function to a variable.
class Combolock:
def _init_(self,num1,num2,num3):
self.x = [num1,num2,num3]
def next(self, state):
print "Enter combination"
combo = raw_input(">")
if combo == self.x[state]:
print "Correct"
return 1
else:
print "Wrong"
return 0
def lock(self):
currentState = 0
while currentState < 2:
temp = next(currentState)
if temp == 1:
currentState = currentState + 1
else:
currentState = 99
print "ALARM"
When I call the lock function, I get an error at the line
temp = next(currentState)
saying that an int object is not an iterator.
You should use self.next(currentState), as you want the next method in the class scope.
The function next is global and next(obj) works only if obj is an iterator.
You might want to have a look at the yield statement in the python documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With