뺄셈 연산자 코딩 중인데 실행 해보면 cnt1은 2행에서 주은 beepers 개수이고 cnt2를 1행에서 주운 beepers 라고 두고 beepers의 개수 차이 만큼 drop beepers를 해야하는데 cnt1>=cnt2 인 경우에는 잘 실행이 되는데 반대로 cnt2>cnt1 인 경우에 계속 beepers1 개를 놓고 종료되는데 뭐가 문제 인지 모르겠음 ,, temp로 cnt1 +10 받고 해당 값에서 cnt2 뺸 값을 다시 cnt1 에 저장하고 싶은데 뭐가 문제 일까요 .. from cs1robots import * load_world("./worlds/sub2.wld") hubo = Robot() hubo.set_pause(0.5) cnt1=0 cnt2=0 ans=0 def turn_right(robot): for i in range(3): robot.turn_left() def move(): while(1): if not hubo.front_is_clear(): break hubo.move() def pick_up(cnt1): cnt1=0 while(1): if hubo.on_beeper(): hubo.pick_beeper() cnt1+=1 else: turn_right(hubo) hubo.move() break return cnt1 def pick_down(cnt1,cnt2,ans): cnt2=0 while(1): if hubo.on_beeper(): hubo.pick_beeper() cnt2+=1 else: break if ans!=0: cnt1-=ans # Subtract instead of add ans=0
if cnt1<cnt2: temp=cnt1+10 temp=-cnt2 cnt1=tmep ans+=1
if cnt1>=cnt2: # Check if the count is negative cnt1 -= cnt2 for _ in range(cnt1>0): hubo.drop_beeper() hubo.turn_left() hubo.turn_left() hubo.move() hubo.turn_left() hubo.move() hubo.turn_left() hubo.turn_left() return ans hubo.turn_left() hubo.move() turn_right(hubo) move() for _ in range(1): cnt1 = pick_up(cnt1) cnt2 = pick_down(cnt1,cnt2,ans)