在不同条件下打印一个变量的两个值
Printing two values of one variable under different conditions
请考虑以下陈述:
sum_value = fixed_value - current_value
,
其中 fixed_value
是常数,current_value
是 thresholds
的函数;
thresholds
有两个 threshold_level
值:thresholds = [10, 20]
;
我需要找到threshold_level = 10
对应的sim_value
到threshold_level = 20
对应的sim_value
的比例,即final_sim_value = sim_value_at_10/sim_value_at_20
.
代码部分为
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)
给出了这个输出:
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
能否请您纠正我或提出适当的解决方案?
您是否尝试获得此结果?
thresholds = [10, 20]
fixed_value = 100
current_values = []
for threshold_value in thresholds:
current_values.append(fixed_value + threshold_value - 5)
print('sim_value_multi(10) is ', current_values[0])
print('sim_value_multi(20) is ', current_values[1])
print('final_sim_value is ', current_values[0]/current_values[1])
输出
sim_value_multi(10) is 105
sim_value_multi(20) is 115
final_sim_value is 0.9130434782608695
请考虑以下陈述:
sum_value = fixed_value - current_value
,
其中 fixed_value
是常数,current_value
是 thresholds
的函数;
thresholds
有两个 threshold_level
值:thresholds = [10, 20]
;
我需要找到threshold_level = 10
对应的sim_value
到threshold_level = 20
对应的sim_value
的比例,即final_sim_value = sim_value_at_10/sim_value_at_20
.
代码部分为
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)
给出了这个输出:
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
能否请您纠正我或提出适当的解决方案?
您是否尝试获得此结果?
thresholds = [10, 20]
fixed_value = 100
current_values = []
for threshold_value in thresholds:
current_values.append(fixed_value + threshold_value - 5)
print('sim_value_multi(10) is ', current_values[0])
print('sim_value_multi(20) is ', current_values[1])
print('final_sim_value is ', current_values[0]/current_values[1])
输出
sim_value_multi(10) is 105
sim_value_multi(20) is 115
final_sim_value is 0.9130434782608695