Guest User

Untitled

a guest
Dec 26th, 2016
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.04 KB | None | 0 0
  1. # coding: utf8
  2. #Программа расчета заработной платы
  3.  
  4. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  5. #Функция расчета заработной платы
  6. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. def Calc():
  8.     #Рассчитываем количество столбцов
  9.     SumString = len(open('start.txt', 'r').readlines())
  10.     SumString = SumString - 1
  11.     openFile = open('start.txt', 'r')
  12.     readerFile = openFile.readlines()
  13.     allWorking = readerFile[0][0]+readerFile[0][1]
  14.     allWorking = float(allWorking)
  15.     sumOfSalary = 0
  16.     #Цикл расчета зарплат на каждого
  17.     for i in range(0,SumString,2):
  18.         workingDays = readerFile[i+2][0]+readerFile[i+2][1]
  19.         workingDays = int(workingDays)
  20.         salary = ''
  21.         lengthOfString = len(readerFile[i+2])
  22.         for j in range(3,lengthOfString - 1):
  23.              salary += readerFile[i + 2][j]
  24.         salary = int(salary)
  25.         calculationFormula = (salary * workingDays) / allWorking
  26.         sumOfSalary = sumOfSalary + calculationFormula
  27.     openFile.close()
  28. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  29. #Функция сохранения в файл
  30. #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  31. def Save():
  32.     SumString = len(open('start.txt', 'r').readlines())
  33.     SumString = SumString - 1
  34.     openFile = open('start.txt', 'r')
  35.     writeFile = open('stop.txt', 'w')
  36.     readerFile = openFile.readlines()
  37.     allWorking = readerFile[0][0]+readerFile[0][1]
  38.     allWorking = float(allWorking)
  39.     sumOfSalary = 0
  40.     writeFile.writelines("+------------------------------------------+-----+------------+------------+\n")
  41.     writeFile.writelines("|                 Фамилия                  | Дни |   Оклад    |  Зарплата  |\n")
  42.     writeFile.writelines("+------------------------------------------+-----+------------+------------+\n")
  43.     for i in range(0,SumString,2):
  44.         workingDays = readerFile[i+2][0]+readerFile[i+2][1]
  45.         workingDays = int(workingDays)
  46.         salary = ''
  47.         lengthOfString = len(readerFile[i+2])
  48.         for j in range(3,lengthOfString - 1):
  49.              salary += readerFile[i + 2][j]
  50.         workerName = ''
  51.         lengthOfString = len(readerFile[i + 1])
  52.         for j in range(0, lengthOfString - 1):
  53.             workerName += readerFile[i + 1][j]
  54.         salary = int(salary)
  55.         calculationFormula = (salary * workingDays) / allWorking
  56.         sumOfSalary = sumOfSalary + calculationFormula
  57.    writeFile.writelines("|",str(workerName).ljust(40),"|",str(workingDays).rjust(3),"|",str(round(salary,2)).rjust(10),"|",str(round(calculationFormula,2)).rjust(10),"|\n")
  58.     openFile.close()
  59.     writeFile.writelines("+------------------------------------------+-----+------------+------------+\n")
  60.     writeFile.writelines("| Итого                                                       |  ",str(round(sumOfSalary,2)),"|\n")
  61.     writeFile.writelines("+------------------------------------------+-----+------------+------------+\n")
  62.     writeFile.close()
  63.  
  64. Calc()
  65. Save()
Advertisement
Add Comment
Please, Sign In to add comment