Срочно на *PYTHON* пжпжжпжпжпжп ДАЮ МНОГО БАЛЛОВ И СДЕЛАЮ ЛУЧШИМ
Класс Покупатель: Фамилия, Имя, Отчество, Адрес, Номер кредитной карточки, Номер банковского счета; Конструктор; Методы: установка значений атрибутов, получение значений атрибутов, вывод информации. Создать массив объектов данного класса. Вывести список покупателей в алфавитном порядке и список покупателей, у которых номер кредитной карточки находится в заданном диапазоне.
Answers & Comments
Ответ:
class Buyer:
def __init__(self, last_name, first_name, middle_name, address, credit_card_number, bank_account_number):
self.last_name = last_name
self.first_name = first_name
self.middle_name = middle_name
self.address = address
self.credit_card_number = credit_card_number
self.bank_account_number = bank_account_number
def set_last_name(self, last_name):
self.last_name = last_name
def set_first_name(self, first_name):
self.first_name = first_name
def set_middle_name(self, middle_name):
self.middle_name = middle_name
def set_address(self, address):
self.address = address
def set_credit_card_number(self, credit_card_number):
self.credit_card_number = credit_card_number
def set_bank_account_number(self, bank_account_number):
self.bank_account_number = bank_account_number
def get_last_name(self):
return self.last_name
def get_first_name(self):
return self.first_name
def get_middle_name(self):
return self.middle_name
def get_address(self):
return self.address
def get_credit_card_number(self):
return self.credit_card_number
def get_bank_account_number(self):
return self.bank_account_number
def display(self):
print(self.last_name, self.first_name, self.middle_name, self.address, self.credit_card_number, self.bank_account_number)
def main():
buyers = []
buyers.append(Buyer('Smith', 'John', 'James', '123 Main St.', '1234567890123456', '123456123456'))
buyers.append(Buyer('Jones', 'Mary', 'Ann', '456 Main St.', '1234567890123457', '123456123457'))
buyers.append(Buyer('Brown', 'William', 'Robert', '789 Main St.', '1234567890123458', '123456123458'))
buyers.append(Buyer('Johnson', 'Patricia', 'Ann', '012 Main St.', '1234567890123459', '321654321654'))
buyers.sort(key=lambda x: x.last_name)
for buyer in buyers:
buyer.display()
print()
for buyer in buyers:
if buyer.credit_card_number >= '1234567890123457' and buyer.credit_card_number <= '1234567890123458':
buyer.display()
if __name__ == '__main__':
main()