-
-
Save Kroppeb/1c91e05b9f85880f0372c42c425930cc to your computer and use it in GitHub Desktop.
The Ancient Knights Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Knight: | |
def __init__(self, name): | |
self.name = name | |
self.l = len(name) | |
self.honor = 0 | |
def quest1(self): | |
if self.l > 6: | |
self.honor += 1 | |
def quest2(self): | |
if not (self.l - self.honor % 2): | |
self.honor += 1 | |
def quest3(self): | |
if self.name != "Lancelot": # aka not a cheating mouthbreather | |
self.honor += 1 | |
else: | |
self.honor -= 1 | |
def quest4(self): | |
if len(set(self.name)) == self.l: | |
self.honor+= 1 | |
quests = [quest1, quest2, quest3, quest4] | |
round_table = [ "Lancelot", "Gawain", "Geraint", | |
"Percival", "Gareth", "Belivere", "Galahad"] | |
knights = [] | |
for name in round_table: | |
knight = Knight(name) | |
for quest in knight.quests: | |
quest(knight) | |
knights.append(knight) | |
knights.sort(key=lambda x: x.honor, reverse=True) | |
best_knight = knights[0] | |
print(best_knight.name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment