Last active
November 21, 2016 15:35
-
-
Save dz0/69811d97250e949cdc133310e94afb83 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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