I passed "The Warriors" mission on my PC (python 3.7.4),
but in "check" mode on checkio, an error caused.
From: https://py.checkio.org/mission/the-warriors/solve/
Error description:
return iterencode(o, 0), File "/usr/local/lib/python3.8/json/encoder.py", line 179, in default, raise TypeError(f'Object of type {o.class.name} ',TypeError: Object of type method is not JSON serializable,,During handling of the above exception, another exception occurred:,,Traceback (most recent call last):, File "/home/site/checkio/runners/py32.py", line 486, in , rundata = echosendrecvjson(globals()'do' + rundata['do']), File "/home/site/checkio/runners/py32.py", line 255, in echosendrecvjson, error = u'TypeError: {0} is wrong data type'.format(cgi.escape(str(type(result)))),AttributeError: module 'cgi' has no attribute 'escape',
My solution:
class Warrior:
health = 50
attack = 5
def is_alive(self):
if self.health > 0:
return True
else:
return False
class Knight(Warrior):
attack = Warrior.attack + 2
def fight(unit_1, unit_2):
while unit_1.health > 0 and unit_2.health > 0:
unit_2.health = unit_2.health - unit_1.attack
if unit_2.health > 0:
unit_1.health = unit_1.health - unit_2.attack
else:
return True
else:
return False
Created at: 2019/09/12 12:02; Updated at: 2019/09/13 07:15
The question is resolved.