PorisulkiP

Номер 5

Jul 5th, 2022 (edited)
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. from random import *
  2.  
  3. def generation():
  4.   ''' Генерируется список чисел согласно условию '''
  5.   global M, N
  6.   N = randint(0, 10000)
  7.   M = randint(-1000000, 1000000)
  8.  
  9.   for x in range(N):
  10.       data.append(randint(-1000000, 1000000))
  11.    
  12.   # матрица записывается в файл
  13.   f = open("in-5.txt", "w")
  14.   f.write(str(data))
  15.   f.close()
  16.   data.clear()
  17.  
  18. def openFileAndReadData():
  19.   ''' Считывается файл с данными '''
  20.   global M, N
  21.   answer = 0
  22.   with open("in-5.txt") as f:
  23.     for line in f:
  24.         data.append([int(x) for x in line.replace("[", "").replace("]", "").replace(",", "").split()])
  25.   f.close()
  26.   for array in data:
  27.     for x in array:
  28.         if x > M:
  29.             answer += 1;
  30.   print (f'N: {N}\nM: {M}\nanswer: {answer}')
  31.  
  32. data = []
  33.  
  34. generation()
  35. openFileAndReadData()
Add Comment
Please, Sign In to add comment