Created
June 12, 2012 22:40
-
-
Save juanpabloaj/2920582 to your computer and use it in GitHub Desktop.
ejemplo python: suma columna
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
dato1 1 10 | |
dato2 2 20 | |
dato3 3 30 | |
# dasadads | |
dato4 4 40 | |
dato5 5 50 | |
# dads | |
dato6 6 60 | |
dato7 7 70 | |
dato8 8 80 | |
dato9 9 90 | |
dato10 10 100 |
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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
for i in range(5): | |
nombre = 'salida0' + str(i) + '.txt' | |
archivo = open(nombre,'a') | |
archivo.write(str(i)+'\n') | |
archivo.close() |
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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
def media(lista): | |
largo = len(lista) | |
suma = sum(lista) | |
return suma/largo | |
archivo = open('datos.txt') | |
valores = [] | |
for l in archivo: | |
if '#' not in l: | |
l = l.replace('\n','') | |
leidos = l.split('\t') | |
print leidos | |
valores.append(int(leidos[2])) | |
print media(valores) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment