Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
def let_me_count_the_ways(love_object): ... solution in Clear category for I Love Python! by kynnjo
def i_love_python():
"""
Let's explain why do we love Python.
"""
return How_do_I_love_thee('Python')
LOVE_THRESHOLD = 100
def How_do_I_love_thee(what):
"""
Go nuts.
"""
if what in MYLOVES:
love = MYLOVES[what].let_me_count_the_ways()
if love == 0:
avowal = '%s? meh...' % what
else:
avowal = 'I love %s' % what
if love < 0:
avowal += ' NOT'
if abs(love) > LOVE_THRESHOLD + __TDD_CORRECTION:
avowal += '!'
else:
avowal = '%s who?' % what
return avowal
class Love(object):
"""
Implement Little Black-Book entry.
"""
def __init__(love_object, **kwargs):
love_object.ways = kwargs
def let_me_count_the_ways(love_object):
return sum(love_object.ways.values())
CENSORED_IN_THE_NAME_OF_PEACE = {}
MYLOVES = dict(C=Love(**CENSORED_IN_THE_NAME_OF_PEACE),
Clojure=Love(**CENSORED_IN_THE_NAME_OF_PEACE),
CommonLisp=Love(**CENSORED_IN_THE_NAME_OF_PEACE),
FORTRAN90=Love(**CENSORED_IN_THE_NAME_OF_PEACE),
Haskell=Love(**CENSORED_IN_THE_NAME_OF_PEACE),
Java=Love(**CENSORED_IN_THE_NAME_OF_PEACE),
JavaScript=Love(**CENSORED_IN_THE_NAME_OF_PEACE),
MATLAB=Love(**CENSORED_IN_THE_NAME_OF_PEACE),
Mathematica=Love(**CENSORED_IN_THE_NAME_OF_PEACE),
ObjectiveC=Love(**CENSORED_IN_THE_NAME_OF_PEACE),
OCaml=Love(**CENSORED_IN_THE_NAME_OF_PEACE),
Perl=Love(**CENSORED_IN_THE_NAME_OF_PEACE),
Prolog=Love(**CENSORED_IN_THE_NAME_OF_PEACE),
PseudoCode=Love(fast=-10000,
easy_to_read=100,
easy_to_write=100,
easy_to_debug=-100,
oop_support=0,
scope_control=10,
macros=10,
regexes=0,
package_system=-100,
builtins=100),
Python=Love(fast=3,
easy_to_read=10,
easy_to_write=10,
easy_to_debug=7,
oop_support=8,
scope_control=-5,
macros=-5,
regexes=4,
package_system=-2,
builtins=10),
Racket=Love(**CENSORED_IN_THE_NAME_OF_PEACE),
Ruby=Love(**CENSORED_IN_THE_NAME_OF_PEACE),
Scheme=Love(**CENSORED_IN_THE_NAME_OF_PEACE),
Smalltalk=Love(**CENSORED_IN_THE_NAME_OF_PEACE),
)
__TDD_CORRECTION = \
min(0, MYLOVES['Python'].let_me_count_the_ways() - LOVE_THRESHOLD - 1)
LOVE_THRESHOLD += __TDD_CORRECTION # All's fair in love
if __name__ == '__main__':
assert i_love_python() == "I love Python!"
Nov. 21, 2014
Comments: