SW.AI 트랙/python
[Python] 파이썬 기초 - if 조건문, while 반복문
AI 봇
2022. 12. 16. 10:24
if 조건문
- 조건은 참(True) 또는 거짓(False) 값을 가질 수 있습니다.
if it rains:
listen_to_class()
else:
play_baseball()
# 또 다른 예시
if True:
print("welcome helloworld")
if False:
print("Sorry"
if 3 < 5:
print("3 is less than 5")
else:
print("3 is large than 5")
비퍼감지하기
# 비퍼를 앞으로 9칸 전진시키면서 경로에 있는 비퍼를 줍도록 하는 코딩
# 비퍼가 한 칸 앞으로 간다 > 비퍼가 있는지 확인한다 > 비퍼가 있다면 비퍼를 줍니다
def move_and_picl():
hubo.move()
if hubo.on_beeper():
hubo.pick_beeper()
for i in range(9):
move_and_pick()
# 비퍼가 없을 때는 비퍼를 떨어뜨리는 코딩
if not hubo.on_beeper():
bubo.drop_beeper()
- not 키워드는 조건을 반대로 바꿉니다. not True 는 False 이고, not False 는 True 입니다.
else
# 4 X 4 메트릭스안에 있는 hubo가 벽을 따라 이동하는 코딩
def move_or_turn()
if hubo.front_is_clear():
hubo.move()