Created
July 31, 2020 11:46
-
-
Save neg3ntropy/effa6c774f515efa99124e76561dea3e to your computer and use it in GitHub Desktop.
il pulcino py
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
from dataclasses import dataclass | |
@dataclass | |
class Strofa: | |
nome: str | |
verso: str | |
ripetizioni: int | |
anche: bool = False | |
@property | |
def maschile(self): | |
return self.nome.endswith(("e", "o")) | |
@property | |
def articolo_det(self): | |
return "il" if self.maschile else "la" | |
@property | |
def articolo_ind(self): | |
return "un" if self.maschile else "una" | |
def intro(self): | |
if (self.anche): | |
s = f"In radio c'è anche {self.articolo_ind} {self.nome}" | |
else: | |
s = f"In radio c'è {self.articolo_ind} {self.nome}" | |
for _ in range(0, 2): | |
print(s) | |
def ritornello(self, precendenti, ripetizioni=None): | |
s = f"E {self.articolo_det} {self.nome} {self.verso}" | |
print(s) | |
if ripetizioni is None: | |
ripetizioni = self.ripetizioni - 1 | |
if precendenti: | |
strofa = precendenti.pop() | |
strofa.ritornello(precendenti, ripetizioni) | |
else: | |
for _ in range(ripetizioni): | |
print(s) | |
class Finale(Strofa): | |
def ritornello(self, precendenti): | |
super().ritornello([]) | |
strofa = precendenti[0] | |
print(f"E {strofa.articolo_det} {strofa.nome} oh oh") | |
canzone = [ | |
Strofa("pulcino", "pio", 6), | |
Strofa("gallina", "coo", 5), | |
Strofa("gallo", "corococo", 4, True), | |
Strofa("tacchino", "glugluglu", 3), | |
Strofa("piccione", "trru", 4), | |
Strofa("gatto", "miao", 3, True), | |
Strofa("cane", "baubau", 4, True), | |
Strofa("capra", "mee", 3), | |
Strofa("agnello", "bee", 4), | |
Strofa("mucca", "mooo", 5), | |
Strofa("toro", "muuu", 4, True), | |
Finale("trattore", "brum", 3) | |
] | |
for i, strofa in enumerate(canzone): | |
strofa.intro() | |
strofa.ritornello(canzone[0:i]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment