Skip to content

Instantly share code, notes, and snippets.

@SebastianDorobantu
Last active April 25, 2020 18:14
Show Gist options
  • Save SebastianDorobantu/2b17e32bb43af880dbd0a604e5075766 to your computer and use it in GitHub Desktop.
Save SebastianDorobantu/2b17e32bb43af880dbd0a604e5075766 to your computer and use it in GitHub Desktop.
"""Iterator fabrica de masini pt Examen practic de Sebi Dorobantu
Prin introducerea a seriei de inceput a zilei respective si numarului de masini produse arata nr de loturi cat si seriile masinilor cu volan pe stanga/dreapta"""
import os
import sys
class Iterator():
"""
Iteratorul propiu zis
"""
def __init__(self, serie: int, bucati: int):
"""
:param serie:
:param bucati:
"""
self.serie = serie
self.bucati = bucati
self.lots = list(range(self.serie // 20, ((self.serie + self.bucati) // 20) + 1))
def __iter__(self):
"""
:return:
"""
return self
def __next__(self):
"""
:return:
"""
if len(self.lots) == 0:
raise StopIteration
return self.lots.pop(0)
class Obiect():
"""
Obiectul care va fii creat
"""
def __init__(self, serieb: int, bucatib: int):
"""
:param serieb:
:param bucatib:
"""
self.serie = serieb
self.bucati = bucatib
self.__iter = Iterator(serieb, bucatib)
self.dreapta2 = []
self.stanga2 = []
for x in list(range(self.serie, (self.serie + self.bucati))):
if (x % 20) < 10:
self.dreapta2.append(x)
else:
self.stanga2.append(x)
def __iter__(self):
"""
:return:
"""
return self.__iter
def dreapta(self):
"""
Metoda care returneaza seriile masinilor cu volan pe dreapta
:return:
"""
return self.dreapta2
def stanga(self):
"""
Metoda care returneaza seriile masinilor cu volan pe stanga
:return:
"""
return self.stanga2
obj = Obiect(101, 41)
print(obj.stanga())
print(obj.dreapta())
output = open("log.log", 'wt')
for line in obj:
output.write(str(line) + '\n')
output.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment