Advertisement
Guest User

Untitled

a guest
Aug 14th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.27 KB | None | 0 0
  1. import random
  2.  
  3. def wczysc(): #co uruchomienie programu czysci plik.txt
  4.     file = open("losowo.txt", mode="w+")
  5.     file.truncate()
  6.     file.close()
  7.     foo = open("zbior_a.txt", mode="w+")
  8.     foo.truncate()
  9.     foo.close()
  10. wczysc()
  11.  
  12. def losowo(): #stworzenie losowego ciagu znakow
  13.     for i in range(100):
  14.         x=(random.randint(1,100))
  15.         x=str(x)
  16.         file = open("losowo.txt", mode="a+")
  17.         file.write("{}\n".format(x))
  18. losowo()
  19.  
  20. def wskaznik(): #wypisanie ile razy pojawila sie dany argument w liscie
  21.     f = open("losowo.txt", mode="r")
  22.     lista=f.readlines()
  23.     nowa_lista = [int(i) for i in lista]
  24.     plik = open("wskaznik.txt", mode="w+")
  25.     for i in range(100):
  26.         i+= 1
  27.         a =nowa_lista.count(i)
  28.         if i<10:
  29.             plik.write("Cyfra {} pojawila sie {} razy \n".format(i,a))
  30.         else:
  31.             plik.write("Liczba {} pojawila sie {} razy \n".format(i,a))
  32.     f.close()
  33.     plik.close()
  34. wskaznik()
  35.  
  36. def sortowanie(): #wypisanie posortowanej listy do pliku3
  37.     plik = open("losowo.txt",mode="r")
  38.     lista=plik.readlines() #tworzy liste stringow
  39.     nowa_lista = [int(i) for i in lista] #zmienia liste z string na int
  40.     nowa_lista.sort() #segreguje liste int bo kolejnosc numeryczna
  41.     file = open("kolejnosc.txt", mode="w+") #otwiera plik3 w trybie w+
  42.     listastr =[str(item) for item in nowa_lista] #zmienia liste z int na string
  43.     string = "\n".join(listastr) #dodaje nową linijke na koncu
  44.     file.write("{}".format(string)) #zapisuje w pliku stringa
  45.     file.close() #zamyka plik
  46.     plik.close()
  47. sortowanie()
  48.  
  49. def zamienienie():
  50.     file = open("wskaznik.txt", "r")
  51.     zbior = open("zbior_a.txt", 'a+')
  52.     for argumenty in file:
  53.         lista = argumenty.split()
  54.         lista.pop(0)
  55.         lista.pop(1)
  56.         lista.pop(1)
  57.         lista.pop(0)
  58.         lista.pop(1)
  59.         string = " ".join(lista)
  60.         zbior.write("{}".format(string))
  61.     zbior.close()
  62.     file.close()
  63. zamienienie()
  64.  
  65. def najwieksza():
  66.     zbior = open("zbior_a.txt", 'r+')
  67.     print(zbior.readlines())
  68.  
  69.     zbior.close()
  70. najwieksza()
  71.  
  72.  
  73.  
  74. #dodac wypisanie która liczba pojawiła sie najwiecej razy i jakie liczby nie pojawiły sie nigdy
  75. #dodac mozliwosc spytania sie ile i czy dana liczba sie pojawila
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement