Created
June 6, 2012 21:53
-
-
Save igorgue/2885069 to your computer and use it in GitHub Desktop.
Get aprox number in a list
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Create a program that given a requested number gives you | |
the nearest number in a list. | |
Considerations: | |
- The list needs to only contain integers | |
This example is useful when you have only a certain number of | |
images sizes available and you have to pick one for your station | |
collage. | |
e.g.: | |
>>> requested_size = 21 | |
>>> sizes = (1, 2, 3, 19, 29, 10, 22, 3) | |
>>> main(requested_size, sizes) | |
22 | |
""" | |
def main(requested_size, sizes): | |
""" | |
>>> requested_size = 120 | |
>>> sizes = (33, 50, 52, 75, 100, 175, 180, 182, 200, 350) | |
>>> main(requested_size, sizes) | |
100 | |
""" | |
raise NotImplementedError('Write your code here') | |
if __name__ == '__main__': | |
import doctest | |
doctest.testmod() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment