Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import io
- from os import system as System
- from os import path as Path
- from math import ceil as Ceil
- # Структура дома
- class House:
- address = "";
- buildType = "";
- buildDate = "";
- floors = "";
- def __init__ (self, address, buildType, buildDate, floors):
- self.address = address
- self.buildType = buildType
- self.buildDate = buildDate
- self.floors = floors
- def __str__ (self):
- return self.address + " " + self.buildType + " " + self.buildDate + " " + self.floors;
- class Houses:
- listHouse = []
- count = 0
- housesInPage = 5
- def addHouse (self, house):
- #if count(filter(lambda x: x.address == house.address, self.listHouse)) > 0:
- for h in self.listHouse:
- if house.address == h.address:
- print ("Дом по адреcу " + house.address + " уже есть в списке")
- return
- self.listHouse.append(house)
- self.count += 1
- def loadFromFile(self, path):
- if Path.exists(path) == False:
- print ("Файл не найден")
- return
- count = 0;
- with io.open(path, encoding='utf-8') as file:
- for line in file:
- house = line.replace("\n", "").split("|")
- newHouse = House(house[0], house[1], house[2], house[3])
- self.addHouse(newHouse)
- count += 1
- print ("Добавлено " + str(count) + " записей")
- self.count += count
- def printPage(self, numPage):
- maxPage = Ceil(self.count / self.housesInPage);
- print ("Выведена страница " + str(numPage) + " из " + str(maxPage - 1))
- for row in range(int(self.housesInPage) * int(numPage), int(self.housesInPage) * (int(numPage) + 1)):
- if row < self.count:
- print (str(row) + ": " + str(self.listHouse[row]))
- def setHousesInPage(self, count):
- self.housesInPage = int(count)
- System('cls')
- houses = Houses()
- #houses.loadFromFile("result.txt")
- while True:
- print ("1 - Загрузить данные из файла")
- print ("2 - Ввести данные вручную")
- print ("3 - Постраничный вывод записей")
- print ("4 - Установить кол-во записей на странице")
- answer = input()
- System('cls')
- if answer == "1":
- print ("Введите название файла")
- houses.loadFromFile(input())
- if answer == "2":
- print ("Введите адрес, тип, дату постройки и кол-во этажей у здания")
- print ("Разделитель |")
- answer = input().split("|")
- if len(answer) != 4:
- print ("Введены некорректные данные")
- else:
- newHouse = House(answer[0], answer[1], answer[2], answer[3])
- houses.addHouse(newHouse)
- print ("Данные о доме добавлены")
- elif answer == "3":
- if houses.count == 0:
- print ("Нет данных ни об одном доме")
- else:
- maxPage = Ceil(houses.count / houses.housesInPage);
- print ("Введите номер страницы от 0 до " + str(maxPage - 1))
- houses.printPage(input())
- elif answer == "4":
- print ("Введите кол-во записей, которые будут отображаться на странице");
- houses.setHousesInPage(input())
Advertisement