Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # isetehtud funktsioon 1, SENTIDE FAILIST LUGEMINE
- def järjendiks(failinimi):
- #avan tekstifaili
- f=open(failinimi)
- #moodustan listi
- tulemus=[]
- #tegin for tsükli, mis käib iga faili rea ükshaaval läbi
- for rida in f:
- #tegin sõnest täisarvu ja võtsin ära reavahetuse stripiga
- rida=int(rida.strip())
- tulemus=tulemus + [rida]
- f.close()
- return tulemus
- # isetehtud funktsioon 2, EUROSENTIDE SUMMA
- def eurosentide_summa(järjend):
- summa = 0
- eurosendid=[1,2,5,10,20,50]
- for el in järjend:
- if el in eurosendid:
- summa += el
- return summa
- # isetehtud funktsioon 3, TUNDMATUTE SENTIDE SUMMA
- def tundmatute_summa(järjend):
- summa = 0
- eurosendid=[1,2,5,10,20,50]
- for el in järjend:
- # if el in eurosendid == False:
- if el not in eurosendid:
- summa += el
- return summa
- # isetehtud funktsioon 4, VÄHIMA PUNASE SENDI LEIDMINE
- def vähim_punane(järjend):
- vähim = 6
- # kirjuta välja millised on punased sendid
- punased = [1,2,5]
- for el in järjend:
- if el in punased:
- if el < vähim:
- vähim = el
- if vähim == 6:
- vähim = 0
- return vähim
- #isetehtud funktsioon 4, VÄHIMA PUNASE SENDI LEIDMINE vol.2
- def vähim_punane2(järjend):
- punased = [1,2,5]
- leitud_punased = []
- for el in järjend:
- if el in punased:
- leitud_punased += [el]
- #leitud_punased.append(el)
- tulemus = 0
- if len(leitud_punased) > 0:
- tulemus = min(leitud_punased)
- return tulemus
- # TULEMUSTE SALVESTAMINE FAILI
- def kirjuta_faili(eurosentide_summa, tundmatute_summa, vähim_punane):
- f = open('tulemused.txt','w')
- f.write(str(eurosentide_summa) + ' eurosenti.\n')
- f.write(str(tundmatute_summa) + ' senti.\n')
- f.write(str(vähim_punane) + ' on vähim punane sent.')
- f.close()
- järjend = järjendiks('sendid.txt')
- euro_summa = eurosentide_summa(järjend)
- tundmatu_summa = tundmatute_summa(järjend)
- vähim_punane = vähim_punane(järjend)
- vähim_punane2 = vähim_punane2(järjend)
- kirjuta_faili(euro_summa, tundmatu_summa, vähim_punane)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement