Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fileName = 'liczby.txt'
- # 4.1
- z = 0 #number of 0 in line
- j = 0 #number of 1 in line
- howMany = 0
- with open(fileName) as file:
- lines = file.readlines()
- for line in lines:
- z = line.count('0')
- j = line.count('1')
- if z > j:
- howMany = howMany + 1
- print('4.1')
- print(str(howMany) + '\n')
- #4.2
- evenNum = 0
- devidedByEight = 0
- with open(fileName) as file:
- lines = file.readlines()
- for line in lines:
- if line[-2] == '0':
- evenNum = evenNum + 1
- if line[ -4 : -1 ] == '000':
- devidedByEight = devidedByEight + 1
- print('4.2')
- print('Number of even numbers is ' + str(evenNum))
- print('Number of numbers devided by 8 is ' + str(devidedByEight) + '\n')
- #4.3
- rowCount = 0 #number of row
- maxRow = '' #row with maximal number of chars
- minRow = '' #row with minimal number of chars
- maxCount = 0 #maximal number of chars
- minCount = len(line) #minimal number of chars
- maxRowCount = 0
- minRowCount = 0
- with open(fileName) as file:
- lines = file.readlines()
- for line in lines:
- rowCount = rowCount + 1
- if maxCount < len(line):
- maxCount = len(line)
- maxRow = line
- maxRowCount = rowCount
- if maxCount == len(line):
- if line > maxRow:
- maxRow = line
- maxRowCount = rowCount
- if minCount > len(line):
- minCount = len(line)
- minRow = line
- minRowCount = rowCount
- if minCount == len(line):
- if line < minRow:
- minRow = line
- minRowCount = rowCount
- print('4.3')
- print('Maximal number has ' + str(maxCount) + " chars and it's in " + str(maxRowCount) + ' line')
- print('Minimal number has ' + str(minCount) + " chars and it's in " + str(minRowCount) + ' line\n')
Advertisement
Add Comment
Please, Sign In to add comment