The hurdle loop challenge 2 - Moving hurdle - using "while loops" - Reeborg's world

def turn_right():

    turn_left()

    turn_left()

    turn_left()

def jump():

    move()

    turn_left()

    move()

    turn_right()

    move()

    turn_right()

    move()

    turn_left()


number_of_hurdles = 6

while number_of_hurdles > 0:

    if at_goal():

        pause()   

    else:

        jump()

        number_of_hurdles -= 1

        print(number_of_hurdles)



A simpler way to write this code would be:


def turn_right():

    turn_left()

    turn_left()

    turn_left()

def jump():

    move()

    turn_left()

    move()

    turn_right()

    move()

    turn_right()

    move()

    turn_left()

 

while not at_goal():

    jump()


And we will get the same output (keep in mind that the flag location changes every time you run the code):




        

Comments

Popular posts from this blog

Converting student scores to grades (Dictionaries)