Last active
September 8, 2017 15:15
-
-
Save antfarm/1307314 to your computer and use it in GitHub Desktop.
A simple random poem generator inspired by Peter Lustig's "Mein erstes Programm" [http://www.youtube.com/watch?v=RUuUoJzE11g&feature=youtu.be&t=16m20s]
This file contains 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
#!/usr/bin/env python | |
# cf. http://www.youtube.com/watch?v=RUuUoJzE11g&feature=youtu.be&t=16m20s | |
import random | |
class RandomPoem: | |
vowels = ['a', 'e', 'i', 'o', 'u'] | |
consonants = [chr(n) for n in xrange(ord('a'), ord('z')) if not chr(n) in vowels] | |
def vowel(self): | |
return random.choice(self.vowels) | |
def consonant(self): | |
return random.choice(self.consonants) | |
def syllable(self): | |
return self.consonant() + self.vowel() | |
def word(self): | |
return ''.join([self.syllable() for i in xrange(random.randint(1, 5))]) | |
def line(self): | |
return ' '.join([self.word() for i in xrange(random.randint(4, 8))]) | |
def verse(self): | |
return '\n'.join([self.line() for i in xrange(4)]) | |
def title(self): | |
return self.line() | |
def poem(self): | |
return '\n\n'.join([self.title()] + [self.verse() for i in range(3)]) | |
if __name__ == '__main__': | |
print RandomPoem().poem() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
wudi nu reka ti palola fane nufira
ji va voyizeqe kajo
palivapoko buceme su wasopiguva cu ra
beqayace zujita diji tuvajima
cisoxuxiyo su qujajikoco cunomu
juhozaca gocuhodo fehozunome mukeso raquruke kaharovefu ke
wofa nu nizi lu tizohuto wete fineju
qakori ketojomu soce lacerogidi
satejozuqe ji tuwa yukihe masazi xomacohoxe ve fewule
xito sa nu hepofuni mabayehalu yoludesu haleki
ticiximami gewofo buxihu qahujirejo vini suduwo caqi yeyoda
si cedawaba gaqaki di ke
ho dase hamokino namiheyi rofefexage