을 도울 수 있다면
내가 프로그래밍에 새로 온 사람, 좋은 것 몇 가지 단서를 것은 스스로를 해결하기 위해 :
alerts = [(6, 0), (7, 1), (8, 1), (9, 1), (10, 0), (11, 1)]
clock_state = 1
for item in alerts:
hour, alert_flag = item
if alert_flag != clock_state:
print "Clock not ringing at {0}".format(hour)
else:
print "Clock ringing at {0}".format(hour)
clock_state = not clock_state
하나의 작은 조언하지만, 다음 번에 몇 가지 코드를 보여하려고 시도하지 않았더라도, 여기 사람들은 문제를 해결하기위한 노력을 보여주는 질문을 좋아하지 않습니다.
편집 여기에, 0-> 1로 변경 내용 만 보여주고 싶은 당신이가는 경우
: 목록에서 경고 플래그를 가정
alerts = [(6, 0), (7, 1), (8, 1), (9, 1), (10, 0), (11, 1)]
len_alerts = len(alerts)
for index in range(len_alerts - 1):
hour1, alert_flag1 = alerts[index]
hour2, alert_flag2 = alerts[index + 1]
if alert_flag1 == 0 and alert_flag2 == 1:
print "Clock ringing at {0}".format(hour2)
출처
2016-08-16 21:51:09
BPL
정확하게 무엇을 하려는지 알 수 있도록 몇 가지 코드를 제공해주십시오. –