[기초] 화학 실험실

edX의 C Programming: Language Foundations 코스에 나오는 문제입니다.(번역)

물론 파이썬으로도 풀 수 있습니다. 반복문과 조건문, 사용자 입력 받는 방법만 알면 됩니다. 거기서 조금 더 알면 더 쉽게 풀 수 있고요.

University chemists have developed a new process for the manufacturing of a drug that heals wounds extremely quickly. The manufacturing process is very lengthy and requires monitoring the chemicals at all times, sometimes for hours! Entrusting this task to a student is not possible; students tend to fall asleep or not pay close attention after a while. Therefore you need to program an automatic device to monitor the manufacturing of the drug. The device measures the temperature every 15 seconds and provides these measurement to your program.

Your program should first read two integers representing the minimum and maximum safe temperatures. Next, your program should continuously read temperatures (integers) that are being provided by the device. Once the chemical reaction is complete the device will send a value of -999, indicating to you that temperature readins are done. For each recorded temperature that is in the correct range (it could also be equal to the min or max values), your program should display the text "Nothing to report". But as soon as a temperature reaches an unsafe level your program must display the text "Alert!" and stop reading temperatures (although the device may continue sending temperature values).

Examples

Input:
10 20
15 10 20 0 15 -999

Output:
Nothing to report
Nothing to report
Nothing to report
Alert!

Input:
0 100
15 50 75 -999

Output:
Nothing to report
Nothing to report
Nothing to report

최용 5162

2020년 7월 10일 10:00 오후

목록으로
6개의 답변이 있습니다. 1 / 1 Page

좋은 퀴즈네요

one = input()  # 첫번째입력
two = input()  # 두번째입력

_min, _max = map(int, one.split())
for n in map(int, two.split()):
    if n == -999:
        break
    elif _min <= n <= _max:
        print("Nothing to report")
    else:
        print("Alert!")
        break

그런데 첫번째 예시의 답이 좀 이상하네요.
출력으로 5개가 나와야 하는데 4개만 나와 있습니다.


아.. 문제를 잘못 봤네요. Alert 이후 종료군요 ㅎㅎ
수정했습니다.

박응용

M 2020년 7월 14일 12:10 오전

allowed_temps = input()
datas = input()

[min_temp, max_temp] = allowed_temps.split(' ')
data_list = datas.split(' ')

for data in data_list:
    if data >= min_temp and data <= max_temp:
        print('Nothing to report')
    elif data == -999:
        break
    else:
        print('Alert!')
        break

댓글을 반영하여 다음과 같이 수정합니다. ^^;

allowed_temps = input()
datas = input()

[min_temp, max_temp] = allowed_temps.split(' ')
data_list = datas.split(' ')

for data in data_list:
    if int(data) >= int(min_temp) and int(data) <= int(max_temp):
        print('Nothing to report')
    elif int(data) == -999:
        break
    else:
        print('Alert!')
        break

자료형을 모두 int로 변경했습니다.

wjpark11

M 2020년 7월 14일 12:45 오전

2번째 예시의 결과값이 다르게 나옵니다. - 박응용님, 2020년 7월 14일 12:06 오전 추천 , 대댓글
+1 @박응용님 댓글 보고 왜 그런지 궁금해서 한 줄씩 테스트해보니 정수가 아닌 문자열 비교가 되었네요. >>> min_temp '0' >>> max_temp '100' >>> data_list ['15', '50', '75', '-999'] >>> data_list[0] >= min_temp True >>> data_list[0] <= max_temp # 이 부분이 의도와 다르게 작동합니다 False - 최용님, M 2020년 7월 14일 12:50 오전 추천 , 대댓글
고치고 보니 다음 분 답이 더 좋네요. ㅎ - wjpark11님, 2020년 7월 14일 12:46 오전 추천 , 대댓글
a, b = map(int, input().split())
ls = list(map(int, input().split()))
for i in ls:
    if i == -999: break
    elif a <= i <= b: print('Nothing to report')
    else:
            print('Alert!')
            break

insuhkim

M 2020년 9월 15일 3:19 오후

low = int(input('최저 온도 입력'))
high = int(input('최고 온도 입력'))

while True:
    num = int(input('현재 온도 입력'))
    if num < low or num > high:
        print('Alert!')
        break
    elif num == -999:
        break
    else: print('Nothing to report')

lollo

2021년 11월 22일 1:26 오전

minNum, maxNum = map(int, input().split())
temperatureList = list(map(int, input().split()))

for temperature in temperatureList:
if temperature == -999:
break;

if minNum <= temperature <= maxNum:
    print('Nothing to report')
else:
    print('Alert!')

undeadx

2023년 2월 3일 2:24 오후

cemi=input().split()
e='save'
while e!='Alert':
.....time=input().split()
.....for i in range(len(time)):
.........if int(cemi[0])<=int(time[i])<=int(cemi[1]):
...............print("Nothing to report")
...............i+=1
..........else:
...............e='Alert'
...............print(e)
...............break

khsoep

2024년 4월 2일 10:53 오후