Python: изменить время в зависимости от другой переменной?
I am working on a financial budget and may not be familiar to some of you. I created this script to call parameters from a file parameter: Net=$10'000'000 Extract from file (salary1 =19000, salary2= 15000, salary3 = 19000 sometimes change) parametersAndValues = {} parameterFile = open('Parameter') try: for line in parameterFile: parametersAndValues[line.split()[0]] = int(round(float(line.split()[1]))) finally: parameterFile.close() i1 = parametersAndValues.get('$salary1') i2 = parametersAndValues.get('$salary2') i3 = parametersAndValues.get('$salary3') for parameter in parametersAndValues: ( parameter + ' = ' + str(parametersAndValues.get(parameter))) time1=0.1*(net/salary1) time2 in TSTEP of salary2=time1+time1*(salary1/(salary1+salary2)) time3 of salary3 = time2+time1 I want to update the timesteps under `TSTEP` depending on the salary payment. To see how many months that salary can be paid. If we divided Net 10'000'000/on salary1 19'000=526 Days = which will be 17 months of 31 Days (17*31) The output should be `17*31` which will be pasted under `TSTEP` for the first salary and `27*31` which will be pasted under `TSTEP` for salary 2. The question is, I need to change `3*31` in each TSTEP depending on the salary, and I have no idea of how to do that. The following is a sample `Schedule` file to be updated from `parameter` file: SCHEDULE ##-- First Cycle / WCLSIN Class1 LIQ OPEN RESV 1* $salary1 1* 3500 / / / TSTEP 3*31 / TUNING / / 2* 100 / ##-- Second Cycle WCLSIN Class1 LIQ OPEN RESV 1* $salary2 3500 / / TSTEP 3*31 / TUNING / / 2* 100 / It should be changed to: SCHEDULE ##-- First Cycle / WCLSIN Class1 LIQ OPEN RESV 1* $salary1 1* 3500 / / / TSTEP 17*31 / TUNING / / 2* 100 / ##-- Second Cycle WCLSIN Class1 LIQ OPEN RESV 1* $salary2 3500 / / TSTEP 27*31 / TUNING / / 2* 100 / Again, please if you have any idea of how to do that I would really appreciate it. Best Regards
Что я уже пробовал:
with open('schedule.txt') as f: # Mode 'r' is default, no need to specify. for current_line in f.read().split('\n'): if previous_line == 'TSTEP': new_lines.append(str(time1)) else: new_lines.append(current_line) previous_line = current_line new_text = '\n'.join(new_lines) open('schedule.txt', 'w').write(new_text)
Проблема в том, что есть две ступени, представляющие разные зарплаты, и я не знаю, как сделать вторую зарплату ??