print
, он выводит что-нибудь? </>
и выбирайте там нужный ЯП. #
будет ли ошибка?
class Element (object):
def __init__(self, name):
self.name = name
self.value = None
self.counter = 0
def __repr__(self):
return f'Количество {self.name} {self.value} : {self.counter}'
class Text (object):
elements_names = ['цифр', 'букв']
def __init__(self):
self.text = None
self.elements = dict(
[(name, Element(name) ) for name in self.elements_names])
def set_text(self):
self.text = input('Введите текст: ')
def set_elements(self):
for key in self.elements:
self.elements[key].value = input(f'Какую {key}у ищем? ')
def count_element(self, element):
text = self.text
for symbol in text:
element.counter += int(symbol == element.value)
def count_elements(self):
for key in self.elements:
self.count_element(self.elements[key])
def __repr__(self):
result = '\n'.join([str(self.elements[key]) for key in self.elements])
return result
text = Text()
text.set_text()
text.set_elements()
text.count_elements()
print(text)