Skip to content

Instantly share code, notes, and snippets.

@hschmitt
Created January 25, 2013 18:19
Show Gist options
  • Save hschmitt/4636638 to your computer and use it in GitHub Desktop.
Save hschmitt/4636638 to your computer and use it in GitHub Desktop.
import random
import sys
def ascii_acumulator():
#Check Arguments
acumulador = 0
if len(sys.argv) == 2:
filename = sys.argv[1]
try:
handler = open(filename, "r")
except IOError:
print "El archivo no fue encontrado"
return 0
else:
print "Esta funcion requiere como argumento un archivo de texto"
return 0
while True:
c = handler.read(1)
if not c:
break
ordinal = ord(c)
if ordinal % 2 or ordinal % 5:
acumulador += ordinal
elif ordinal % 3 or ordinal % 7:
acumulador -= ordinal
print acumulador
if __name__ == "__main__":
ascii_acumulator()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment