All pastes #1629227 Raw Edit

Anonymous

public python v1 · immutable
#1629227 ·published 2009-10-19 09:26 UTC
rendered paste body
#!/usr/bin/env python# -*- coding: utf-8 -*-def int_or_exit(num):    try: return int(num)    except ValueError:        print "Malformed input.txt"        exit()def read_or_exit(filename):    try: return open(filename, "r")    except IOError:        print "Cannot open input.txt. Does it exist?"        exit()fin = read_or_exit("input.txt")numlist = fin.read().split()numcount = len(numlist)maxsum = 0try: if int_or_exit(numlist[0]) > 0: maxsum = int_or_exit(numlist[0])except IndexError: passitercycle = 1for num in numlist:    newsum = int_or_exit(num)    if newsum > maxsum: maxsum = newsum    for numx in numlist[itercycle:]:        newsum += int_or_exit(numx)        if newsum > maxsum: maxsum = newsum    itercycle += 1print "Maximal sum is %d" % maxsum