Day 006

AWESOMee·2022년 1월 27일
0

Udemy Python Bootcamp

목록 보기
6/64
post-thumbnail

Udemy Python Bootcamp Day 006

Defining Function

def my_function():
  #Do this
  #Then do this
  #Finally do this

def my_function():
  print("Hello")
  print("Bye")

my_function()

#output
Hello
Bye

Reeborg's World
https://reeborg.ca/reeborg.html?lang=en&mode=python&menu=worlds%2Fmenus%2Freeborg_intro_en.json&name=Hurdle%201&url=worlds%2Ftutorial_en%2Fhurdle1.json


hurdle

def turn_right():
    turn_left()
    turn_left()
    turn_left()
    move()

def jump():
    move()
    turn_left()
    move()
    turn_right()
    turn_right()
    turn_left()

#for구문
for step in range(6):
    jump()

#while구문
number_of_hurdles = 6
while number_of_hurdles > 0:
    jump()
    number_of_hurdles -= 1
    print(number_of_hurdles)

While Loop

while something_is_true:
    #Do something repeatedly
    #Do this
    #Then do this
    #Then do this

if I have some sort of condition that actually never becomes fase, then while loop becomes something known as an infinite loop.


hurdle 2

while at_goal() != True: 
# while not at_goal(): 과 같음
    jump()

hurdle 3

def turn_right():
    turn_left()
    turn_left()
    turn_left()
    move()

def jump():
    turn_left()
    move()
    turn_right()
    turn_right()
    turn_left()

while not at_goal():
    if front_is_clear():
        move()
    else:
        jump()

hurdle 4

def turn_right():
    turn_left()
    turn_left()
    turn_left()
    move()

def jump():
    turn_left()
    while wall_on_right():
        move()

    turn_right()
    turn_right()

    while front_is_clear():
        move()

    turn_left()

while not at_goal():
    if front_is_clear():
        move()
    else:
        jump()

maze

def turn_right():
    turn_left()
    turn_left()
    turn_left()

#내가 쓴답(정말 이게 최선이었니,,, 하지만 무한루프 생성안됨 ㅎ)
while not at_goal():
    if front_is_clear():
        move()
        turn_left()
        if front_is_clear():
            move()
        else:
            turn_right()
    elif right_is_clear():
        turn_right()
        move()
    else:
        turn_left()
        if wall_in_front():
            turn_left()
            move()
        else:
            move()

#답안 <난 쓸데없이 복잡해졌지 왜,, 
while front_is_clear():
    move()
turn_left()

while not at_goal():
#keep repeating the instructions inside this while loop until at_goal becomes true and not true is false
    if right_is_clear():
        turn_right()
        move()
    elif front_is_clear():
        move()
    else:
        turn_left()

profile
개발을 배우는 듯 하면서도

0개의 댓글