Created
January 25, 2013 18:19
-
-
Save hschmitt/4636638 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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