강의

멘토링

커뮤니티

Inflearn Community Q&A

caesiumy's profile image
caesiumy

asked

Jeju Coding Base Camp Code Festival: Python 100 Questions

Problem solving for 99-100

99번에 오류가 살짝 있어서 고쳐봤어요

Written on

·

284

0

rocks = [1, 2, 1, 4]
rabbits = [2, 1, 3]

def sol(rocks, rabbits):
  results = ["pass" for i in range(len(rabbits))]
  
  for i in range((len(rabbits))):
    step = 0

    while step < len(rocks):
      step += rabbits[i]
      print(f'step: {step}')

      if step <= len(rocks):
        rocks[step - 1] -= 1

        if rocks[step - 1] < 0:
          results[i] = 'fail'

      print(rocks)
    print('---------------')

  return results

sol(rocks, rabbits)

배열 크기를 벗어나면 오류가 생겨서 if문으로 걸러줬습니다.

python코테 준비 같이 해요!

Answer

This question is waiting for answers
Be the first to answer!
caesiumy's profile image
caesiumy

asked

Ask a question