0
Hey guys, can anybody help me explain and fix this code plz ?
class Western: def __init__(self,name): self.n = name self.h = 1 def shot(self,other): other.h-=1 print("kjsj") def result(self): if self.h > 0: pass elif self.h <= 0: print(f"{self} die") a = Western("koko") b = Western("uouo") a.shot(b) b.result() # why when a.shot(b) is called , it printed text normally ("kjsj") but when b.result() is called. It showed <main.......so on. I don't know why and I want it print "uouo" die
3 Réponses
+ 4
In the print statement of the result method I think it should be self.n
+ 2
TCorn ,
i would recommend you to run the code in debug / step mode. so you will be able to see each step and what is happening with variables and so on.
you can use
http://www.pythontutor.com/visualize.html#mode=edit
that is quite simple to operate.
0
Oyeah this my silly mistake .thank you guys