Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # coding: utf8
- #Программа расчета заработной платы
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- #Функция расчета заработной платы
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- def Calc():
- #Рассчитываем количество столбцов
- SumString = len(open('start.txt', 'r').readlines())
- SumString = SumString - 1
- openFile = open('start.txt', 'r')
- readerFile = openFile.readlines()
- allWorking = readerFile[0][0]+readerFile[0][1]
- allWorking = float(allWorking)
- sumOfSalary = 0
- #Цикл расчета зарплат на каждого
- for i in range(0,SumString,2):
- workingDays = readerFile[i+2][0]+readerFile[i+2][1]
- workingDays = int(workingDays)
- salary = ''
- lengthOfString = len(readerFile[i+2])
- for j in range(3,lengthOfString - 1):
- salary += readerFile[i + 2][j]
- salary = int(salary)
- calculationFormula = (salary * workingDays) / allWorking
- sumOfSalary = sumOfSalary + calculationFormula
- openFile.close()
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- #Функция сохранения в файл
- #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- def Save():
- SumString = len(open('start.txt', 'r').readlines())
- SumString = SumString - 1
- openFile = open('start.txt', 'r')
- writeFile = open('stop.txt', 'w')
- readerFile = openFile.readlines()
- allWorking = readerFile[0][0]+readerFile[0][1]
- allWorking = float(allWorking)
- sumOfSalary = 0
- writeFile.writelines("+------------------------------------------+-----+------------+------------+\n")
- writeFile.writelines("| Фамилия | Дни | Оклад | Зарплата |\n")
- writeFile.writelines("+------------------------------------------+-----+------------+------------+\n")
- for i in range(0,SumString,2):
- workingDays = readerFile[i+2][0]+readerFile[i+2][1]
- workingDays = int(workingDays)
- salary = ''
- lengthOfString = len(readerFile[i+2])
- for j in range(3,lengthOfString - 1):
- salary += readerFile[i + 2][j]
- workerName = ''
- lengthOfString = len(readerFile[i + 1])
- for j in range(0, lengthOfString - 1):
- workerName += readerFile[i + 1][j]
- salary = int(salary)
- calculationFormula = (salary * workingDays) / allWorking
- sumOfSalary = sumOfSalary + calculationFormula
- writeFile.writelines("|",str(workerName).ljust(40),"|",str(workingDays).rjust(3),"|",str(round(salary,2)).rjust(10),"|",str(round(calculationFormula,2)).rjust(10),"|\n")
- openFile.close()
- writeFile.writelines("+------------------------------------------+-----+------------+------------+\n")
- writeFile.writelines("| Итого | ",str(round(sumOfSalary,2)),"|\n")
- writeFile.writelines("+------------------------------------------+-----+------------+------------+\n")
- writeFile.close()
- Calc()
- Save()
Advertisement
Add Comment
Please, Sign In to add comment