Skip to content

Instantly share code, notes, and snippets.

@Ape
Last active September 23, 2015 14:33
Show Gist options
  • Save Ape/1e688f4618fe0d7a2666 to your computer and use it in GitHub Desktop.
Save Ape/1e688f4618fe0d7a2666 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
class Kartta:
def __init__(self, koko, auto):
self.koko = koko
self.auto = auto
def tulosta(self):
for rivinumero in reversed(range(1, self.koko + 1)):
print(self._rivi(rivinumero))
self._tulosta_vaaka_akseli()
def _symboli(self, koordinaatit):
if koordinaatit == self.auto:
return "A"
else:
return "."
def _rivi_symbolit(self, rivinumero):
yield "{}|".format(rivinumero % 10)
for i in range(1, self.koko + 1):
yield self._symboli((i, rivinumero))
def _rivi(self, rivinumero):
return " ".join(self._rivi_symbolit(rivinumero))
def _tulosta_vaaka_akseli(self):
print(" + " + "- " * self.koko)
print(" " + " ".join((str(i % 10) for i in range(1, self.koko + 1))))
def tulosta_kartta(auto_x, auto_y, kartta_koko):
Kartta(kartta_koko, (auto_x, auto_y)).tulosta()
if __name__ == "__main__":
tulosta_kartta(3, 5, 26)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment