Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. try:
  2. import random as r;
  3. except ImportError:
  4. print( "Nie ma takiego modulu!!!" );
  5.  
  6. def losuj_z_przedzialu( start, stop ):
  7. l = r.randint( start, stop );
  8. return l;
  9.  
  10. def losuj_z_konkretnego_zestawu( l ):
  11. lk = r.choice( l );
  12. return lk;
  13.  
  14. def losuj_decyzje():
  15. d = r.randint( 0, 1 );
  16. return d;
  17.  
  18. def zapisz_plik( lista ):
  19. file = "plik.csv";
  20. try:
  21. f = open( file, 'a' );
  22. except IOError:
  23. print( "Nieudana proba pracy z plikiem!");
  24.  
  25. lista = str( lista );
  26. f.write( lista );
  27. f.write( '\n' );
  28. f.close();
  29.  
  30. def czyszczenie():
  31. file = "plik.csv";
  32. try:
  33. f = open( file, 'w' );
  34. except IOError:
  35. print( "Nieudana proba pracy z plikiem!");
  36.  
  37. f.write( '' );
  38. f.close();
  39.  
  40. class System_decyzyjny:
  41. 'Generator systemu decyzyjnego'
  42.  
  43. liczba_obiektow = 5;
  44. liczba_atrybutow = 4;
  45.  
  46. def wypelnij_i_stworz( self ):
  47. lista = []
  48. for i in range( 0, System_decyzyjny.liczba_atrybutow ):
  49. x = losuj_z_przedzialu( 0, 9 )
  50. #x = losuj_z_konkretnego_zestawu( l = [ 1, 3, 7, 12 ] )
  51. lista.append( x );
  52. y = losuj_decyzje();
  53. lista.append( y );
  54. print( lista );
  55. zapisz_plik( lista );
  56.  
  57. czyszczenie();
  58. for ob in range( 0, System_decyzyjny.liczba_obiektow ):
  59. ob = System_decyzyjny();
  60. ob.wypelnij_i_stworz();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement