#------------------------------------------------------------------ from math import sqrt class HDTV(object): global ar ar = 1.7778 # 16:9 def __init__(self,diag1,diag2): self.diag1 = diag1 self.diag2 = diag2 def height(self): height1 = self.diag1/sqrt(1 + ar**2) height2 = self.diag2/sqrt(1 + ar**2) h = [height1,height2] return h def width(self): width1 = self.diag1/sqrt(1 + (1/ar)**2) width2 = self.diag2/sqrt(1 + (1/ar)**2) w = [width1,width2] return w def area(self): area1 = self.height()[0]*self.width()[0] area2 = self.height()[1]*self.width()[1] a = [area1,area2] return a def display(self): if self.diag2 == 0: print "----------------------------" print "Height 1 =", self.height()[0] print "Width 1 =", self.width()[0] print "Area 1 =", self.area()[0] elif self.diag1 == 0: print "----------------------------" print "Height 2 =", self.height()[1] print "Width 2 =", self.width()[1] print "Area 2 =", self.area()[1] elif self.diag1 != 0 and self.diag2 != 0 and self.diag1 > self.diag2: ratio = self.area()[1]/self.area()[0] print "----------------------------" print "Height 1 =", self.height()[0] print "Width 1 =", self.width()[0] print "Area 1 =", self.area()[0] print "----------------------------" print "Height 2 =", self.height()[1] print "Width 2 =", self.width()[1] print "Area 2 =", self.area()[1] print "----------------------------" print "% Diff =", 100*(1 - ratio) elif self.diag1 != 0 and self.diag2 != 0 and self.diag1 < self.diag2: ratio = self.area()[0]/self.area()[1] print "----------------------------" print "Height 1 =", self.height()[0] print "Width 1 =", self.width()[0] print "Area 1 =", self.area()[0] print "----------------------------" print "Height 2 =", self.height()[1] print "Width 2 =", self.width()[1] print "Area 2 =", self.area()[1] print "----------------------------" print "% Diff =", 100*(1 - ratio) #------------------------------------------------------------------ d1 = float(raw_input("Diagonal 1 =")) d2 = float(raw_input("Diagonal 2 =")) tv = HDTV(d1,d2) print tv.display()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question