import os # check os and set value for clear_cmd if os.name == 'nt': clear_cmd = 'cls' else: clear_cmd = 'clear' # Clear screen os.system(clear_cmd) test_width = [] frames = [] # Get user input print 'Please enter an aspect ratio to test.' ratio_width = int(raw_input('Enter ratio width (ie. 16): ')) ratio_height = int(raw_input('Enter ratio height (ie. 9): ')) print print 'Will find all whole number ratios that are ',ratio_width,':',ratio_height width_min = int(raw_input('From frame width: ')) width_max = int(raw_input('Up to frame width: ')) print # calculate possible widths for i in range(width_min,(width_max+1)): if i % ratio_width == 0: test_width.append(i) else: pass # test if height of possible widths is also divisible by 16 and create tuple list for i in range(len(test_width)): width = test_width[i] height = (test_width[i]/ratio_width)*ratio_height if height % ratio_height == 0: tuple = (width, height) frames.append(tuple) for i in frames: print i
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