Skip to content

Instantly share code, notes, and snippets.

@Doff3n
Created Sep 25, 2013
Embed
What would you like to do?
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