Advertisement
fabis_sparks

LarisaPythonOS

Oct 30th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.61 KB | None | 0 0
  1. import random
  2. ############################# Введём количество строк и столбцов
  3. rows=int(input('Num of rows: '))
  4. cols=int(input('Num of cols: '))
  5. ############################# Сгенерируем массив заданного размера
  6. r=random.randint(1,100)
  7. mas = []
  8. for i in range(rows):
  9.     mas.append([])
  10.     for j in range(cols):
  11.         mas[i].append(r)
  12.         r = random.randint(1,100)  
  13. ############################# Выведем сгенерированный массив
  14. for i in range(rows):
  15.     print(mas[i], "\n")
  16. ############################# Вводим координаты элемента. Номер строки.
  17. m_row=int(input("Enter the number of a row, which will be used in max search:"))
  18. while (m_row>rows or m_row==rows or m_row<0):
  19.      m_row=int(input("Bad Condition. Entered number shouldn't be equals/bigger/smaller than source number of rows: "))
  20. ############################# Номер столбца
  21. m_col=int(input("Enter the number of a col, which will be used in max search:"))
  22. while (m_col>cols or m_col==cols or m_col<0):
  23.      m_col=int(input("Bad Condition. Entered number shouldn't be equals/bigger/smaller than source number of cols: "))
  24. ############################# Debug info
  25. print(m_row,m_col, " = ", mas[m_row-1][m_col-1])
  26. ############################# Теперь найдём максимум
  27. max=0
  28. mm_row=m_row-1
  29. for i in range(0,mm_row,1):
  30.     for j in range(m_col,cols,1):
  31.         if mas[i][j]>max:
  32.             max=mas[i][j]
  33. ############################# Выведем искомый результат
  34. print(max)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement