subject
Computers and Technology, 09.02.2021 07:40 al8ce

I wrote the move function of this phython code: but it is not working here correctly, Karel is only moving one space.
Here are the directions:
YOUR JOB
Karel doesn’t know how to move! Since we aren’t using the built in Karel commands, we’ll have to make the image of Karel move using Python!

Your job is to implement the move() function.

You do not need to worry about running into walls.

You do not need to modify any of the other code function. The final result should have Karel move forward (east) twice, then move in a square. Karel should end on the first street, fourth avenue, facing south.

HINTS
Your move function should change the X_POS and Y_POS variable based on the direction that Karel is facing. For example, if direction is NORTH, then Karel should move in the negative y direction. If direction is SOUTH, then Karel should move in the positive y direction, etc.

Once you update the X_POS or Y_POS, you can then set a new position by calling the .set_position method.

Karel should move a distance of KAREL_SIZE.


# This program creates Karel without any of the builtin Karel commands,
# it makes Karel from scratch using Python.
#
# In this program, we build Karel's World in Python.

NUM_STREETS = 4
NUM_AVES = 4
POINT_SIZE = 3
WORLD_WIDTH = 275
WORLD_HEIGHT = 275
set_size(WORLD_WIDTH, WORLD_HEIGHT)

STREET_HEIGHT = WORLD_HEIGHT // NUM_STREETS
AVE_WIDTH = WORLD_WIDTH // NUM_AVES
PAUSE_TIME = 1000

# Constants for creating Karel
KAREL_IMG_URL = "https://codehs. com/uploads/9657058ec012105e0c5548c 917c29761"
KAREL_SIZE = STREET_HEIGHT
# Starting position for Karel
X_POS = 0
Y_POS = WORLD_HEIGHT - KAREL_SIZE

# represents angles of rotation
EAST = 0
SOUTH = math. radians(90)
WEST = math. radians(180)
NORTH = math. radians(270)

# Creates Karel's world with Karel in the bottom left corner facing east.
def setup_world():
global direction, karel
# Add the points to the grid
for street in range(NUM_STREETS):
for ave in range(NUM_AVES):
x_center = ave * AVE_WIDTH + AVE_WIDTH / 2
y_center = street * STREET_HEIGHT + STREET_HEIGHT / 2
dot = Circle(POINT_SIZE, x_center, y_center)
add(dot)

# Add Karel to the grid
karel = Image(KAREL_IMG_URL)
karel. set_position(X_POS, Y_POS)
karel. set_size(KAREL_SIZE, KAREL_SIZE)
add(karel)

# Variables to keep track of karel and karel's direction
# Set Karel's initial direction
direction = EAST

def turn_left():
global karel, direction

if direction == EAST:
direction = NORTH
elif direction == WEST:
direction = SOUTH
elif direction == NORTH:
direction = WEST
elif direction == SOUTH:
direction = EAST
else:
print("Error: Karel's Direction is not properly set.")
direction = EAST

karel. set_rotation(direction)

# Copy your code from the last exercise
def turn_right():
global karel, direction

if direction == EAST:
direction = SOUTH
elif direction == WEST:
direction = NORTH
elif direction == NORTH:
direction = EAST
elif direction == SOUTH:
direction = WEST
else:
print("Error: Karel's Direction is not properly set.")
direction = WEST

karel. set_rotation(direction)

# Implement this function!
def move():
global X_POS, Y_POS
if direction == EAST:
karel. set_position(X_POS + KAREL_SIZE, Y_POS)
def move_again():
global X_POS, Y_POS
if direction == EAST:
karel. set_position(X_POS + KAREL_SIZE, Y_POS)
def move_move():
global X_POS, Y_POS
if direction == EAST:
karel. set_position(X_POS + KAREL_SIZE, Y_POS)

setup_world()
move()
move_again()
move_move()

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 16:10
What is the ooh? a. omaha occupation handbook b. online occupational c. occupations online d. occupational outlook handbook select the best answer from the choices provided
Answers: 3
question
Computers and Technology, 24.06.2019 00:40
Use a software program or a graphing utility with matrix capabilities to solve the system of linear equations using an inverse matrix. x1 + 2x2 − x3 + 3x4 − x5 = 6 x1 − 3x2 + x3 + 2x4 − x5 = −6 2x1 + x2 + x3 − 3x4 + x5 = 3 x1 − x2 + 2x3 + x4 − x5 = −3 2x1 + x2 − x3 + 2x4 + x5 = 5
Answers: 3
question
Computers and Technology, 24.06.2019 22:30
The a great imaginary circle, or reference line, around earth that is equally distant from the two poles and divides earth into the northern and southern hemispheres.
Answers: 1
question
Computers and Technology, 25.06.2019 02:30
How to delete a question in
Answers: 2
You know the right answer?
I wrote the move function of this phython code: but it is not working here correctly, Karel is only...
Questions
question
Mathematics, 16.12.2020 02:10
question
Mathematics, 16.12.2020 02:10
question
Social Studies, 16.12.2020 02:10
question
Mathematics, 16.12.2020 02:10
question
Mathematics, 16.12.2020 02:10