Codehs All Answers Karel Top 90%
# This function builds a single tower def build_tower(): putBall() move() putBall() move() putBall() # Go back down turnRight() move() move() move() turnRight()
Karel understands a very limited set of instructions. Every complex solution is built from these four basic blocks: move(); : Moves Karel one space forward. turnLeft(); : Rotates Karel 90 degrees to the left. putBall(); : Places one tennis ball on the current square. codehs all answers karel top
putBall(); // Place the last ball at the wall # This function builds a single tower def
def run_leg(): while frontIsClear(): move() jump_hurdle() putBall(); : Places one tennis ball on the current square
Don't write 50 lines and hope it works. Test after each function. Debugging small pieces is much easier than debugging everything at once.
In Karel's grid, a refers to a row, while an avenue refers to a column. If Karel starts at Street 1 and Avenue 3 facing East, and you run the code move(); move(); move(); turnLeft(); move(); , Karel will end up on Street 2, Avenue 6.