Demo entry 6349658

ppi

   

Submitted by anonymous on Feb 24, 2017 at 12:47
Language: Python 3. Code size: 463 Bytes.

from fractions import gcd

hp = int(input('Horizontal pixels: ') or 3840)
vp = int(input('Vertical pixels: ') or 2160)
s = float(input('Screen size: ') or 65)

ppi = ((hp ** 2 + vp ** 2) ** 0.5) / s

g = gcd(hp, vp)

vd = (s ** 2 / ((hp / vp) ** 2 + 1)) ** 0.5
hd = (hp / vp) * vd

print('\nPPI: {:,.1f}'.format(ppi))
print('\nAspect ratio: {:g}:{:g}'.format(int(hp / g), int(vp / g)))
print('\nScreen dimensions: {:,.2f}x{:,.2f}\n'.format(hd, vd))

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).