Please consider the statements below:
sum_value = fixed_value - current_value
,
where fixed_value
is a constant, and current_value
is a function of thresholds
;
thresholds
has two threshold_level
values: thresholds = [10, 20]
;
I need to find a rato of sim_value
corresponding to threshold_level = 10
to sim_value
corresponding to threshold_level = 20
, that is final_sim_value = sim_value_at_10/sim_value_at_20
.
The code part is
JavaScript
x
28
28
1
thresholds = [10, 20]
2
fixed_value = 100
3
4
for threshold_level in thresholds:
5
current_value = 5 - threshold_level
6
sim_value = fixed_value - current_value
7
8
def sim_value_multi(threshold_level):
9
if threshold_level == 10:
10
sim_value_at_10 = sim_value
11
return sim_value_at_10
12
if threshold_level == 20:
13
sim_value_at_20 = sim_value
14
return sim_value_at_20
15
16
final_sim_value = sim_value_multi(10)/sim_value_multi(20)
17
18
print('sim_value_multi(10) is ', sim_value_multi(10))
19
print('sim_value_multi(20) is ', sim_value_multi(20))
20
print('final_sim_value is ', final_sim_value)
21
22
print('--------------------')
23
final_sim_value = sim_value_multi(10)/sim_value_multi(20)
24
25
print('sim_value_multi(10) is ', sim_value_multi(10))
26
print('sim_value_multi(20) is ', sim_value_multi(20))
27
print('final_sim_value is ', final_sim_value)
28
which gives this output:
JavaScript
1
11
11
1
sim_value_multi(10) is 105
2
sim_value_multi(20) is 105
3
final_sim_value is 1.0
4
sim_value_multi(10) is 115
5
sim_value_multi(20) is 115
6
final_sim_value is 1.0
7
--------------------
8
sim_value_multi(10) is 115
9
sim_value_multi(20) is 115
10
final_sim_value is 1.0
11
Could you please correct me or suggest a proper solution?
Advertisement
Answer
Are you trying to obtain this result ?
JavaScript
1
10
10
1
thresholds = [10, 20]
2
fixed_value = 100
3
current_values = []
4
for threshold_value in thresholds:
5
current_values.append(fixed_value + threshold_value - 5)
6
7
print('sim_value_multi(10) is ', current_values[0])
8
print('sim_value_multi(20) is ', current_values[1])
9
print('final_sim_value is ', current_values[0]/current_values[1])
10
Output
JavaScript
1
4
1
sim_value_multi(10) is 105
2
sim_value_multi(20) is 115
3
final_sim_value is 0.9130434782608695
4