Answer the question
In order to leave comments, you need to log in
Why is the condition not firing in Python code?
Введите максимально допустимый уровень опасности: 0.01
Приблизительная глубина безопасной кладки: 0.732421875 м
def calculate_hazard_level_by_depth(depth):
result = depth ** 3 - 3 * depth ** 2 - 12 * depth + 10
return result
acceptable_hazard_level = float(input('Введите максимально допустимый уровень опасности: '))
while True:
min_depth = 0
max_depth = 4.0
current_depth = (max_depth + min_depth) / 2
# значение в минус - давление, значение в плюс - радиация
# вычисляем минимальный уровень радиации
current_hazard = calculate_hazard_level_by_depth(current_depth)
print(current_depth, current_hazard)
if current_hazard < 0:
max_depth = current_depth
elif current_hazard > acceptable_hazard_level:
min_depth = current_depth
else:
break
print(current_depth)
# print('Приблизительная глубина безопасной кладки:', safe_depth, 'м')
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question