from blomst import Blomst class Blomsterkasse: def __init__(self, bredde, lengde): self._bredde = bredde self._blomster = [] for i in range(self._bredde): self._blomster.append(None) def plantBlomst(self, blomst): for i in range(self._bredde): if self._blomster[i] == None: self._blomster[i] = blomst return True return False def vannAlleBlomster(self): for blomst in self._blomster: if blomst is not None: blomst.vann() def nestDag(self): for blomst in self._blomster: if blomst is not None: blomst.nesteDag() def skrivUtInfoOmBlomster(self): for blomst in self._blomster: if blomst is not None: print(blomst) def ryddIBedd(self): for i in range(self._bredde): if self._blomster[i] is not None and not self._blomster[i].hentStatus(): self._blomster[i] = None def antallBlomster(self): antall = 0 for blomst in self._blomster: if blomst is not None: antall += 1 return antall def __str__(self): string = '' string += 'Bredden: ' + str(self._bredde) string += '\nAntal blomster:' + str(self.antallBlomster()) string += '\n---Info om blomstene---\n' for blomst in self._blomster: if blomst is not None: string += blomst.__str__() return string if __name__ == '__main__': kasse = Blomsterkasse(3,1) blomst1 = Blomst('Rose',2) blomst2 = Blomst('blaaveis',3) blomst3 = Blomst('hvitveis',4) print(kasse) kasse.plantBlomst(blomst1) kasse.plantBlomst(blomst2) kasse.plantBlomst(blomst3) print(kasse)