Monstera

matura2015

Oct 8th, 2022 (edited)
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.86 KB | None | 0 0
  1. fileName = 'liczby.txt'
  2.  
  3. # 4.1
  4.  
  5. z = 0 #number of 0 in line
  6. j = 0 #number of 1 in line
  7. howMany = 0
  8.  
  9. with open(fileName) as file:
  10.     lines = file.readlines()
  11.     for line in lines:
  12.         z = line.count('0')
  13.         j = line.count('1')
  14.         if z > j:
  15.             howMany = howMany + 1
  16.  
  17. print('4.1')
  18. print(str(howMany) + '\n')
  19.  
  20. #4.2
  21.  
  22. evenNum = 0
  23. devidedByEight = 0
  24.  
  25. with open(fileName) as file:
  26.     lines = file.readlines()
  27.     for line in lines:
  28.         if line[-2] == '0':
  29.             evenNum = evenNum + 1
  30.         if line[ -4 : -1 ] == '000':
  31.             devidedByEight = devidedByEight + 1
  32.  
  33. print('4.2')
  34. print('Number of even numbers is ' + str(evenNum))
  35. print('Number of numbers devided by 8 is ' + str(devidedByEight) + '\n')            
  36.  
  37. #4.3
  38.  
  39. rowCount = 0 #number of row
  40. maxRow = '' #row with maximal number of chars
  41. minRow = '' #row with minimal number of chars
  42. maxCount = 0 #maximal number of chars
  43. minCount = len(line) #minimal number of chars
  44. maxRowCount = 0
  45. minRowCount = 0
  46.  
  47. with open(fileName) as file:
  48.     lines = file.readlines()
  49.     for line in lines:
  50.         rowCount = rowCount + 1
  51.         if maxCount < len(line):
  52.             maxCount = len(line)
  53.             maxRow = line
  54.             maxRowCount = rowCount
  55.         if maxCount == len(line):
  56.             if line > maxRow:
  57.                 maxRow = line
  58.                 maxRowCount = rowCount
  59.         if minCount > len(line):
  60.             minCount = len(line)
  61.             minRow = line
  62.             minRowCount = rowCount
  63.         if minCount == len(line):
  64.             if line < minRow:
  65.                 minRow = line
  66.                 minRowCount = rowCount
  67.  
  68.  
  69. print('4.3')
  70. print('Maximal number has ' + str(maxCount) + " chars and it's in " + str(maxRowCount) + ' line')
  71. print('Minimal number has ' + str(minCount) + " chars and it's in " + str(minRowCount) + ' line\n')
Tags: Matura 2015
Advertisement
Add Comment
Please, Sign In to add comment