Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Army Units by libertypi
class Army:
def train_swordsman(self, name):
return Swordsman(self.sword, name, self.continent, "swordsman")
def train_lancer(self, name):
return Lancer(self.lancer, name, self.continent, "lancer")
def train_archer(self, name):
return Archer(self.acher, name, self.continent, "archer")
class AsianArmy(Army):
def __init__(self):
self.sword = "Samurai"
self.lancer = "Ronin"
self.acher = "Shinobi"
self.continent = "Asian"
class EuropeanArmy(Army):
def __init__(self):
self.sword = "Knight"
self.lancer = "Raubritter"
self.acher = "Ranger"
self.continent = "European"
class Soldier:
def __init__(self, title, name, continent, type):
self.title = title
self.name = name
self.continent = continent
self.type = type
def introduce(self):
return f"{self.title} {self.name}, {self.continent} {self.type}"
class Swordsman(Soldier):
pass
class Lancer(Soldier):
pass
class Archer(Soldier):
pass
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
my_army = EuropeanArmy()
enemy_army = AsianArmy()
soldier_1 = my_army.train_swordsman("Jaks")
soldier_2 = my_army.train_lancer("Harold")
soldier_3 = my_army.train_archer("Robin")
soldier_4 = enemy_army.train_swordsman("Kishimoto")
soldier_5 = enemy_army.train_lancer("Ayabusa")
soldier_6 = enemy_army.train_archer("Kirigae")
assert soldier_1.introduce() == "Knight Jaks, European swordsman"
assert soldier_2.introduce() == "Raubritter Harold, European lancer"
assert soldier_3.introduce() == "Ranger Robin, European archer"
assert soldier_4.introduce() == "Samurai Kishimoto, Asian swordsman"
assert soldier_5.introduce() == "Ronin Ayabusa, Asian lancer"
assert soldier_6.introduce() == "Shinobi Kirigae, Asian archer"
print("Coding complete? Let's try tests!")
July 14, 2020
Comments: