Computers and Technology
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()

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 18:00, Geo777
Suppose an astronomer discovers a large, spherical-shaped body orbiting the sun. the body is composed mostly of rock, and there are no other bodies sharing its orbit. what is the best way to categorize this body? a. planet b. moon c. comet d. asteroid
Answers: 1
image
Computers and Technology, 23.06.2019 04:20, RandomLollipop
Which network media uses different regions of the electromagnetic spectrum to transmit signals through air? uses different regions of the electromagnetic spectrum to transmit signals through air.
Answers: 2
image
Computers and Technology, 23.06.2019 07:30, kimhoss2
What are ways to switch windows in excel? check all that apply. on the status bar, click the windows button, and then click the file name. on the task bar, click to display the excel jump list, and then click the file name. on the view tab, in the window group, click switch windows, and then click the file name. on the review tab, in the viewing group, click files, and then click the file name.
Answers: 1
image
Computers and Technology, 24.06.2019 06:30, meganwintergirl
Ineed to know the anwser to all these questions
Answers: 2
Do you know the correct answer?
I wrote the move function of this phython code: but it is not working here correctly, Karel is only...

Questions in other subjects:

Konu
SAT, 05.05.2020 05:02
Konu
Mathematics, 05.05.2020 05:02