/ Published in: Python
Find sum of 2 smallest number
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#!/usr/bin/python import logging import csv from inspect import currentframe, getframeinfo logger = logging.getLogger('root') FORMAT = "[%(filename)s:%(lineno)s - %(funcName)20s() ] %(message)s" logging.basicConfig(format=FORMAT) #logger.setLevel(logging.NOTSET) logger.setLevel (logging.DEBUG) def sum(array): logger.debug ("array function") if len(array) < 2: print "Error! Array small" return -1 array.sort() print "Sorted array : %s" %array print "%d %d" % (array[0],array[1]) return array[0] + array[1] if __name__ == "__main__": mylist = [10,3,4,1,7] x = sum(mylist) print "sum of 2 min numbers : %d" %x