Advertisement
fabis_sparks

Untitled

Dec 4th, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. import random
  2. ############################# Введём размер матрицы
  3. rows=int(input('Size of matrix: '))
  4. ############################# Введем пороговое значение для суммы
  5. treshold=int(input("Input treshold: "))
  6.  
  7. mas = []
  8. necmas=[]
  9. ############################# Сгенерируем массив
  10. for i in range(rows):
  11.     mas.append([])
  12.     for j in range(rows):
  13.         r = random.randint(1,100)  
  14.         mas[i].append(r)
  15.      
  16. sum=0
  17. x=0
  18. ############################# Выведем сгенерированный массив
  19. print("Show us a randomized array")
  20. for i in range(rows):
  21.     print(mas[i], "\n")
  22. ############################# Приступим к сортировке
  23. print("Let's start to view necessary arrays")
  24. necmas.append([])
  25. for i in range(rows):
  26.      for j in range(rows):
  27.         if(sum<treshold or sum==treshold):
  28.             necmas[x].append(mas[i][j])
  29.             sum=sum+mas[i][j]
  30.         else:
  31.             necmas.append([])
  32.             x=x+1
  33.             print("Array #", x,": ", necmas[x-1])
  34.             print("Sum: ", sum)
  35.             print("=====================")
  36.             sum=mas[i][j]
  37.             necmas[x].append(mas[i][j])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement