Advertisement
ollikolli

aineiston_suodatus koodi

Mar 6th, 2023
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. def suodata_laskut():
  2.     with open("oikeat.csv") as tiedosto:
  3.         if tiedosto.read() == "":
  4.             with open("laskut.csv") as tiedosto:
  5.                 vastaus = 0
  6.                 for rivi in tiedosto:
  7.                     rivi = rivi.replace("\n", "")
  8.                     osat = rivi.split(";")
  9.                     if "-" in osat[1]:
  10.                         vähennys = osat[1].split("-")
  11.                         vastaus = int(vähennys[0]) - int(vähennys[1])
  12.                     elif "+" in osat[1]:
  13.                         summa = osat[1].split("+")
  14.                         vastaus = int(summa[0]) + int(summa[1])
  15.                     if int(vastaus) == int(osat[2]):
  16.                         with open("oikeat.csv", "a") as tiedosto:
  17.                             tiedosto.write(rivi+"\n")
  18.                     else:
  19.                         with open("vaarat.csv", "a") as tiedosto:
  20.                             tiedosto.write(rivi+"\n")
  21.  
  22. if __name__ == "__main__":
  23.     suodata_laskut()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement