Skip to content

Instantly share code, notes, and snippets.

@Doff3n
Created September 25, 2013 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Doff3n/6696207 to your computer and use it in GitHub Desktop.
Save Doff3n/6696207 to your computer and use it in GitHub Desktop.
Python String Calculator
import sys;
def add(numbers):
result=0; sep=","; nums=numbers
if(numbers.startswith("//")):
lines = numbers.splitlines()
pattern=lines[0][2:]
if(pattern[0]=="[" and pattern[pattern.length-1]=="]"):
pattern=pattern[1:pattern.length-1]
sep=pattern; nums=lines[1]
nums = nums.replace("\n",sep).split(sep)
for n in nums:
i=int(n)
if(i<0):
raise ValueError("negative not allowed")
if(i<=1000):
result+=i
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment