[구름]소금물의 농도 구하기

YongJun·2024년 12월 21일

[코딩테스트]

목록 보기
15/22

소금물의 농도 구하기

input = input()
user_input,water_input = map(float, input.split())

salt = user_input * 0.07
weight = user_input + water_input
result = (salt/weight) * 100

print(f"{result:.2f}")

문제에서는 3번째 자리부터 버림으로 하라고 했기 때문에 위 코드는 정상적으로 작동하지만 print 부분에서 반올림을 수행하기 때문에 일부 케이스에서 FAIL의 결과값을 가진다

import math

input = input()  
user_input, water_input = map(float, input.split())  # 공백을 기준으로 나누어 리스트를 만든다.

salt = user_input * 0.07  #7%의 농도의 소금 양 구하기
weight = user_input + water_input  #전체 소금물 계산
result = (salt / weight) * 100  #소금물 농도 계산

result = math.floor(result * 100) / 100 #문제에서 요구하는 소수 2번째 자리까지만 출력 시키기

print(f"{result:.2f}")
profile
Student

0개의 댓글