Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # Print the contents of the files listed on the command line.
- import sys, os
- from string import *
- if len(sys.argv) == 1:
- sys.exit("Usage: "+sys.argv[0]+" files...");
- for fn in sys.argv[1:]:
- fin = open(fn, 'r')
- filename = find(fn, '.')
- if filename != -1:
- fn = fn[0:filename] + ".tsv"
- fin2 = open(fn, 'w')
- while 1:
- line = fin.readline().rstrip()
- if not line: break;
- parts = split(line, ',')
- newline = ""
- for part in parts[0:]:
- newline = newline + part + "\t"
- newline = newline + "\n"
- fin2.write(newline)
- fin.close()
- fin2.close()
- ######### vtora zadaca
- #!/usr/bin/python
- import sys, os, glob
- from string import *
- totalka = 0
- files = glob.glob('*.py')
- files += glob.glob('*.sh')
- for file in files[0:]:
- #print str(os.stat(file).st_size) + " za " + file
- totalka += os.stat(file).st_size
- print totalka
- ######### treta zadaca
- #!/usr/bin/python
- import sys, os, glob
- from string import *
- if len(sys.argv) == 1:
- sys.exit("Usage: "+sys.argv[0]+" files...");
- mapa = {}
- for fn in sys.argv[1:]:
- fin = open(fn, 'r')
- while 1:
- line = fin.readline().rstrip()
- if not line: break;
- line = line.replace(".", "")
- line = line.replace(",", "")
- line = line.replace("!", "")
- line = line.replace(";", "")
- line = line.replace("\t", "")
- line = line.replace("?", "")
- parts = split(line, ' ')
- for part in parts[0:]:
- part = part.upper();
- if len(part.) > 3:
- if mapa.has_key(part):
- mapa[part]+=1;
- else:
- mapa[part]=1
- fin.close()
- for key, value in sorted(mapa.iteritems(), key=lambda (k,v): (v,k), reverse=True):
- print "%s: %s" % (key, value)
- ######### cetvrta zadaca
- #!/usr/bin/python
- import sys, os, glob
- from string import *
- brojnapredmeti=0
- predmeti = []
- pprosek = {}
- fin = open("rezultati.txt", 'r')
- line = fin.readline().rstrip()
- if not line: sys.exit("Prazen fajl!");
- parts = split(line, '\t')
- for part in parts[1:]:
- predmeti.append(part)
- brojnapredmeti+=1
- pprosek[part] = 0
- print "Rabotime so slednive predmeti:"
- print predmeti
- brojnastudenti=0
- tmpprosek=0
- while 1:
- line = fin.readline().rstrip()
- if not line: break;
- brojnastudenti+=1
- tmpprosek=0
- brojac=0
- parts = split(line, '\t')
- for part in parts[1:]:
- pprosek[predmeti[brojac]]+=int(part)
- tmpprosek+=int(part)
- brojac+=1
- odnos = (tmpprosek*1.0)/brojnapredmeti
- print parts[0] + " ima prosek: " + str(odnos)
- print
- print "Prosek za predmeti:"
- for predmet in predmeti[0:]:
- tmpprosek = (pprosek[predmet]*1.0)/brojnastudenti
- print predmet + ": " + str(tmpprosek)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement