Created
April 11, 2022 13:20
-
-
Save l-arkadiy-l/a90b4d9811b32f6acf6729b1967a68f9 to your computer and use it in GitHub Desktop.
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
class Person: | |
def __init__(self, name, middle_name, surname, private_work): | |
self.name = name | |
self.surname = surname | |
self.middle_name = middle_name | |
self.private_work = private_work | |
def get_phone(self): | |
if "private" in self.private_work: | |
return self.private_work["private"] | |
else: | |
return | |
def get_name(self): | |
return self.surname, self.name, self.middle_name | |
def get_work_phone(self): | |
if "work" in self.private_work: | |
return self.private_work["work"] | |
else: | |
return | |
def get_sms_text(self): | |
return (f"Уважаемый {self.name} {self.middle_name}!" | |
f"Примите участие в нашем беспроигрышном конкурсе для физических лиц") | |
class Company: | |
def __init__(self, company, type_company, phones, *employees): | |
self.company_name = company | |
self.type_company = type_company | |
self.phones = phones | |
self.employees = employees | |
def get_phone(self): | |
if 'contact' in self.phones: | |
return self.phones['contact'] | |
for employee in self.employees: | |
if 'work' in employee.private_work: | |
return employee.private_work['work'] | |
return | |
def get_name(self): | |
return self.company_name | |
def get_sms_text(self): | |
return (f"Для компании {self.company_name} есть супер предложение! " | |
f"Примите участие в нашем беспроигрышном конкурсе для {self.type_company}") | |
def send_sms(*args): | |
for current_object in args: | |
if current_object.__class__.__name__ == 'Company': | |
number = current_object.get_phone() | |
if number: | |
print(f"Отправлено СМС на номер {number}" | |
f" с текстом: {current_object.get_sms_text()}") | |
else: | |
print(f"Не удалось отправить сообщение абоненту: " | |
f"{current_object.company_name}") | |
else: | |
if not current_object.get_phone(): | |
print(f"Не удалось отправить сообщение абоненту:" | |
f" {' '.join(current_object.get_name())}") | |
else: | |
print(f"Отправлено СМС на номер {current_object.get_phone()}" | |
f" с текстом: {current_object.get_sms_text()}") | |
person1 = Person("Ivan", "Ivanovich", "Ivanov", {"private": 123, "work": 456}) | |
person2 = Person("Ivan", "Petrovich", "Petrov", {"private": 789}) | |
person3 = Person("Ivan", "Petrovich", "Sidorov", {"work": 789}) | |
person4 = Person("John", "Unknown", "Doe", {}) | |
company1 = Company("Bell", "ООО", {"contact": 111}, person3, person4) | |
company2 = Company("Cell", "АО", {"non_contact": 222}, person2, person3) | |
company3 = Company("Dell", "Ltd", {"non_contact": 333}, person2, person4) | |
send_sms(person1, person2, person3, person4, company1, company2, company3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment