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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 21:30, elsauceomotho
Im doing this last minute and literally none of my neighbors or people that my dad works with use excel so if anyone could me make up an example
Answers: 1
image
Computers and Technology, 24.06.2019 12:50, opgbadwolf5
When is it most apprpriate for a development team to change the definition of done
Answers: 1
image
Computers and Technology, 24.06.2019 13:10, Briannas5022
Write a program that has a conversation with the user. the program must ask for both strings and numbers as input. the program must ask for at least 4 different inputs from the user. the program must reuse at least 3 inputs in what it displays on the screen. the program must perform some form of arithmetic operation on the numbers the user inputs. turn in your .py file as well as a screenshot of your program's output. include comments in your code to explain how it works an example program run might look like (have fun with this and be creative): ‘what is your name? ’ “josh” ‘, josh. what is your favorite color? ’ “green” ‘mine too. do you also like ice cream? ’ “no” ‘josh, how old are you? ’ “40” ‘ and how many siblings do you have? ’’ “3” ‘that means you are one of 4 kid(s). is green the favorite color of anyone else in your house? ’
Answers: 3
image
Computers and Technology, 25.06.2019 03:40, NBASTARK4523
Acurrent vehicle registration expires at of the first owner listed on the registration form. a. stretch and flex b. bend and break c. wear down d. bounce around
Answers: 1
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 in other subjects:

Konu
History, 25.07.2019 13:10