E
E
esmolnik2018-10-28 12:35:16
Python
esmolnik, 2018-10-28 12:35:16

How to solve the problem with the calculation of coefficients?

How to write code correctly so that the program would count from 1 to 6000, one coefficient for each unit, let's say 1 = 0.4. And from 6000 to 10000 it is these 4000 thousand according to another coefficient, let's say 1 = 0.6?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Rostislav Grigoriev, 2018-10-28
@esmolnik

def some_calc_func(param):
    coef = 0.4
    if 6000 < param < 10000:
        coef = 0.6
    # здесь код вычислений, возвращается результат перемножения, к примеру
    return coef * param
 
for i in range(1, 10001):
    print(some_calc_func(i))

If you want the result to be 6000 * 0.4 + 1000 * 0.6 at 7000 , then:
COEF = 0.4
INC_COEF = 0.6
INC_COEF_FACTOR = 6000

def calc_result(value):
    if value > INC_COEF_FACTOR:
        return (value - INC_COEF_FACTOR) * INC_COEF + INC_COEF_FACTOR * COEF
    return value * COEF

N
NaName, 2018-10-28
@NaName

2 rounds one after the other

for i in range(1, 6000):
    coefficient = 0.4
for i in range(6000, 10001):
    coefficient = 0.6

E
esmolnik, 2018-10-28
@esmolnik

The process loops. Tell me what I wrote wrong please.
my_input = input ('xxx')
for my_input in range(0, 6000):
coefficient = 0.4;
for my_input in range(6001, 10000):
coefficient = 0.6;
print(my_input * coefficient)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question