I am new to python and trying to use python for learning DSA. While trying this code it is not working properly.
test.addOne()
should increase the num
value but it is not .
and also the while loop is infinite
It will be great if somebody could help me. Thanks in advance.
class Test: def __init__(self): self.num = 1 def addOne(self): if self.num >= 1 and self.num <= 10 : self.num+1 else: self.num = 0 def getNum(self): return self.num test =Test() while test.getNum() != 0: test.addOne() print( test.getNum() )
Top comments (2)
sorry all , after 3 hours to troubleshooting , i got the error , it is
self.num+1
should beself.num += 1
Great job figuring it out! :D