Advertisement
Guest User

Untitled

a guest
Mar 29th, 2015
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. # isetehtud funktsioon 1, SENTIDE FAILIST LUGEMINE
  2. def järjendiks(failinimi):
  3.  
  4. #avan tekstifaili
  5. f=open(failinimi)
  6.  
  7. #moodustan listi
  8. tulemus=[]
  9.  
  10. #tegin for tsükli, mis käib iga faili rea ükshaaval läbi
  11. for rida in f:
  12.  
  13. #tegin sõnest täisarvu ja võtsin ära reavahetuse stripiga
  14. rida=int(rida.strip())
  15. tulemus=tulemus + [rida]
  16. f.close()
  17. return tulemus
  18.  
  19. # isetehtud funktsioon 2, EUROSENTIDE SUMMA
  20. def eurosentide_summa(järjend):
  21. summa = 0
  22. eurosendid=[1,2,5,10,20,50]
  23. for el in järjend:
  24. if el in eurosendid:
  25. summa += el
  26. return summa
  27.  
  28. # isetehtud funktsioon 3, TUNDMATUTE SENTIDE SUMMA
  29. def tundmatute_summa(järjend):
  30. summa = 0
  31. eurosendid=[1,2,5,10,20,50]
  32. for el in järjend:
  33. # if el in eurosendid == False:
  34. if el not in eurosendid:
  35. summa += el
  36. return summa
  37.  
  38. # isetehtud funktsioon 4, VÄHIMA PUNASE SENDI LEIDMINE
  39. def vähim_punane(järjend):
  40. vähim = 6
  41. # kirjuta välja millised on punased sendid
  42. punased = [1,2,5]
  43. for el in järjend:
  44. if el in punased:
  45. if el < vähim:
  46. vähim = el
  47. if vähim == 6:
  48. vähim = 0
  49. return vähim
  50.  
  51. #isetehtud funktsioon 4, VÄHIMA PUNASE SENDI LEIDMINE vol.2
  52. def vähim_punane2(järjend):
  53. punased = [1,2,5]
  54. leitud_punased = []
  55. for el in järjend:
  56. if el in punased:
  57. leitud_punased += [el]
  58. #leitud_punased.append(el)
  59. tulemus = 0
  60. if len(leitud_punased) > 0:
  61. tulemus = min(leitud_punased)
  62. return tulemus
  63.  
  64. # TULEMUSTE SALVESTAMINE FAILI
  65. def kirjuta_faili(eurosentide_summa, tundmatute_summa, vähim_punane):
  66. f = open('tulemused.txt','w')
  67. f.write(str(eurosentide_summa) + ' eurosenti.\n')
  68. f.write(str(tundmatute_summa) + ' senti.\n')
  69. f.write(str(vähim_punane) + ' on vähim punane sent.')
  70. f.close()
  71.  
  72. järjend = järjendiks('sendid.txt')
  73. euro_summa = eurosentide_summa(järjend)
  74. tundmatu_summa = tundmatute_summa(järjend)
  75. vähim_punane = vähim_punane(järjend)
  76. vähim_punane2 = vähim_punane2(järjend)
  77. kirjuta_faili(euro_summa, tundmatu_summa, vähim_punane)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement