In [11]:
f = open("podaci/iliad.txt", "r")
br_redova = 0
for red in f:
br_redova += 1
f.close()
print("Datoteka iliad.txt ima", br_redova, "redova")
In [9]:
f = open("podaci/iliad.txt", "r")
br_knjiga = 0
for red in f:
if red[:4] == "BOOK":
br_knjiga += 1
f.close()
print("Homerova Ilijada ima", br_knjiga, "knjige")
In [10]:
def prebroj_podstr(p, s):
broj = 0
n = len(p)
for i in range(len(s) - n + 1):
if p == s[i:i+n]:
broj += 1
return broj
f = open("podaci/iliad.txt", "r")
br_ahil = 0
br_hektor = 0
for red in f:
br_ahil += prebroj_podstr("Achilles", red)
br_hektor += prebroj_podstr("Hector", red)
f.close()
print("Ahil se pominje", br_ahil, "puta")
print("Hektor se pominje", br_hektor, "puta")
In [12]:
def prebroj_podstr(p, s):
broj = 0
n = len(p)
for i in range(len(s) - n + 1):
if p == s[i:i+n]:
broj += 1
return broj
f = open("podaci/iliad.txt", "r")
ceo_tekst = f.read()
f.close()
print("Ahil se pominje", prebroj_podstr("Achilles", ceo_tekst), "puta")
print("Hektor se pominje", prebroj_podstr("Hector", ceo_tekst), "puta")
In [18]:
red = "4,A++,Cocomelon - Nursery Rhymes,441,53163816,33519273951"
In [20]:
s = red.split(",")
In [22]:
s
Out[22]:
In [23]:
f = open("podaci/Top 25 YouTubers.csv", "r")
red = f.readline() # prvi red predstavlja zaglavlje tabele i njega preskacemo
br_vid = 0
naj_kanal = ""
for red in f:
s = red.split(",")
if int(s[3]) > br_vid:
br_vid = int(s[3])
naj_kanal = s[2]
f.close()
print("Najvise videa je objavio kanal", naj_kanal)
In [1]:
f = open("pitagora.txt", "w")
f.write("Kvadrat nad hipotenuzom,")
f.write("to zna svako dete,")
f.write("jednak je zbiru kvadrata")
f.write("nad obe katete.")
f.close()
In [2]:
f = open("pitagora.txt", "w")
f.write("Kvadrat nad hipotenuzom,\n")
f.write("to zna svako dete,\n")
f.write("jednak je zbiru kvadrata\n")
f.write("nad obe katete.\n")
f.close()
In [5]:
f = open("pesmica.txt", "w")
for i in range(9):
f.write(str(10 - i) + " little monkeys were jumping on a bed\n")
f.write("one fell off and bumped its head.\n")
f.write("Mommy called the doctor and the doctor said:\n")
f.write("'No more monkeys jumping on the bed!'\n")
f.write("\n")
# poslednja strofa
f.write("1 little monkey was jumping on a bed\n")
f.write("it fell off and bumped its head.\n")
f.write("Mommy called the doctor and the doctor said:\n")
f.write("'Put those monkeys back to bed!'\n")
f.close()
In [4]:
f = open("podaci/iliad.txt", "r")
g = open("podaci/duzine.txt", "w")
for red in f:
n = len(red)
g.write(str(n) + "\n")
f.close()
g.close()
In [7]:
vol1 = open("podaci/iliad_vol1.txt", "a")
vol1.write("The Project Gutenberg eBook of The Iliad, by Homer\n")
vol1.write("Translated by Edward, Earl of Derby\n")
vol1.write("\n")
vol1.write("\n")
datoteke = ["podaci/BOOK01.txt", "podaci/BOOK02.txt", "podaci/BOOK03.txt", "podaci/BOOK04.txt",
"podaci/BOOK05.txt", "podaci/BOOK06.txt", "podaci/BOOK07.txt", "podaci/BOOK08.txt",
"podaci/BOOK09.txt", "podaci/BOOK10.txt", "podaci/BOOK11.txt", "podaci/BOOK12.txt"]
for dat in datoteke:
f = open(dat, "r");
s = f.read()
vol1.write(s)
vol1.write("\n")
vol1.write("\n")
f.close()
vol1.write("END OF VOLUME I.\n")
vol1.close()
No comments:
Post a Comment