'Printing two values of one variable under different conditions
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
thresholds = [10, 20]
fixed_value = 100
for threshold_level in thresholds:
current_value = 5 - threshold_level
sim_value = fixed_value - current_value
def sim_value_multi(threshold_level):
if threshold_level == 10:
sim_value_at_10 = sim_value
return sim_value_at_10
if threshold_level == 20:
sim_value_at_20 = sim_value
return sim_value_at_20
final_sim_value = sim_value_multi(10)/sim_value_multi(20)
print('sim_value_multi(10) is ', sim_value_multi(10))
print('sim_value_multi(20) is ', sim_value_multi(20))
print('final_sim_value is ', final_sim_value)
print('--------------------')
final_sim_value = sim_value_multi(10)/sim_value_multi(20)
print('sim_value_multi(10) is ', sim_value_multi(10))
print('sim_value_multi(20) is ', sim_value_multi(20))
print('final_sim_value is ', final_sim_value)
which gives this output:
sim_value_multi(10) is 105
sim_value_multi(20) is 105
final_sim_value is 1.0
sim_value_multi(10) is 115
sim_value_multi(20) is 115
final_sim_value is 1.0
--------------------
sim_value_multi(10) is 115
sim_value_multi(20) is 115
final_sim_value is 1.0
Could you please correct me or suggest a proper solution?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
