Skip to content

Instantly share code, notes, and snippets.

@dz0
Last active November 21, 2016 15:35
Show Gist options
  • Select an option

  • Save dz0/69811d97250e949cdc133310e94afb83 to your computer and use it in GitHub Desktop.

Select an option

Save dz0/69811d97250e949cdc133310e94afb83 to your computer and use it in GitHub Desktop.
#coding=utf-8
# duomenys paimami iš failo, sugeneruoto pagal https://gist.github.com/dz0/b92294a7829256e08e725bd0ce595e57
""" failo pvz: spejimai.log
20 6 [5, 3, 1, 0, 20]
15 4 [5, 3, 4]
10 4 [5, 3, 1, 0, 20]
15 13 [5, 3, 4, 13]
"""
# gudresnis failo atidarymas (tinka ir rašymui) -- nereikia pačiam rūpintis close
with open("spejimai.log", "r") as f: # a - append, w - write, r - read
eilutes = f.readlines()
for eil in eilutes:
# print( eil )
# išsitraukiam duomenis
eil = eil.replace(", ", ",") # pakeiciam, kad po kablelių nebūtų tarpų
dalys = eil.split(" ") # suskaidom eilutę pagal tarpus
# print(dalys)
riba, tikslas, spejimai = dalys # sąrašo reikšmės "išdalinamos" kintamiesiems
riba = int(riba) # txt paverčiam į skaičių
tikslas = int(tikslas) # txt paverčiam į skaičių
spejimai = eval( spejimai ) # eval - reiškia evaluate -- įvertina txt reikšmę kaip Python interpretatorius
# analizuosim
proporcija = 100 * tikslas/riba # koks santykis tikslo su riba
print( proporcija )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment