Python_level_2/2lession/Display.py

39 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from math import sqrt
from Rect import Rect
class Display(Rect):
def __init__(self, diagonal, height: int, width: int):
super().__init__(height, width)
self.diagonal = diagonal
self.dpi = round((sqrt(pow(self.height, 2) + pow(self.width, 2))) / self.diagonal, 2)
def get_dpi(self):
return self.dpi
def get_pixel_num(self):
return super().area()
def area(self):
return round((self.height / self.get_dpi()) * (self.width / self.get_dpi()), 1)
def get_resolution_px(self):
return self.height, self.width
def main():
samsung_mon = Display(19, 1920, 1080) # 19", 1920x1080 пикселей
print(samsung_mon.area()) # площадь в кв. дюймах, либо в кв. м
print(samsung_mon.perimeter())
samsung_mon.rotate()
samsung_mon.rotate()
print(samsung_mon.get_dpi()) # количество точек на дюйм
print(samsung_mon.get_pixel_num()) # сколько мегапикселей у экрана
print(samsung_mon.get_resolution_px()) # разрешение в пикселях в виде кортежа: (1920, 1080)
if __name__ == '__main__':
main()