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

1st Jul 2021, 2:13 PM
TCorn
TCorn - avatar
3 Réponses
+ 4
In the print statement of the result method I think it should be self.n
1st Jul 2021, 2:59 PM
Lisa
Lisa - avatar
+ 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.
1st Jul 2021, 3:00 PM
Lothar
Lothar - avatar
0
Oyeah this my silly mistake .thank you guys
2nd Jul 2021, 1:08 AM
TCorn
TCorn - avatar