Untitled Flashcards Set

  1. Question: 1

    What’s wrong with this code?

    def go():
    move()
    move()

    def go():
    move()
    move()

    move()
    go()
    go()

    1. The go function is called twice

    2. The go function has a syntax error

    3. Correct Answer

      The go function has been defined twice

    4. go is not a command that Karel understands

  2. Correct

    Question: 2

    How many total times will Karel move in this program?

    move()
    for i in range(5):
    move()
    put_ball()

    1. 1

    2. 5

    3. Correct Answer

      6

    4. 7

  3. Correct

    Question: 3

    What is wrong with this for loop?

    for i in range = 5;
    move()

    A. The for loop uses a semicolon(;) instead of colon(:)

    B. It should say range(5) instead of range = 5

    1. A

    2. B

    3. Correct Answer

      A and B

    4. The for loop is correct

  4. Correct

    Question: 4

    What is the proper format for a single line comment in Karel?

    1. Correct Answer

      # This is a comment

    2. // This is a comment

    3. /* This is a comment

    4. This is a comment

  5. Correct

    Question: 5

    What does the mystery function do?

    def mystery():
    while no_balls_present():
    move()

    1. Correct Answer

      Karel moves until it is on a ball

    2. Karel moves once if there is no ball present

    3. Karel moves until it puts down a ball

    4. Karel checks if there is no ball on the current spot and then moves once

  6. Correct

    Question: 6

    Which of the following is not a valid condition to go in an if statement for Karel?

    1. balls_present()

    2. front_is_clear()

    3. left_is_blocked()

    4. Correct Answer

      turn_left()
  7. Correct

    Question: 7

    Say Karel is on a location with one tennis ball. After the following code runs, how many tennis balls will there be at that location?

    for i in range(3):
    if balls_present():
    take_ball()
    else:
    put_ball()
    put_ball()

    1. 0

    2. Correct Answer

      1

    3. 2

    4. 6

  8. Correct

    Question: 8

    What condition should be used in this while loop to get Karel to pick up all the tennis balls on the current location?

    while ________ :
    take_ball()

    1. no_balls_present()

    2. Correct Answer

      balls_present()
    3. front_is_clear()

    4. take_ball()

  9. Correct

    Question: 9

    Why does a programmer indent their code?

    1. Helps show the structure of the code.

    2. Easier for other people to understand.

    3. In Python, it is used to help determine what parts of a code are included in a code block, such as an if statement or for loop.

    4. Correct Answer

      All of the above

  10. Correct

    Question: 10

    How can we teach Karel new commands?

    1. For loop

    2. While loop

    3. Correct Answer

      Define a new function

    4. The main function

  11. Correct

    Question: 11

    Say you want to write a program to have Karel put down 300 tennis balls. Which control structure would you use?

    1. If statement

    2. While loop

    3. Correct Answer

      For loop

    4. Nested while loop

  12. Correct

    Question: 12

    Super Karel starts at Street 1, Avenue 1, facing East in a 5x5 world. What will happen after this code runs?

    move()
    move()
    turn_right()
    move()

    1. Karel ends on street 1, avenue 3

    2. Karel ends on street 2, avenue 3

    3. This code won’t run because of a syntax error

    4. Correct Answer

      Karel will crash into a wall

  13. Correct

    Question: 13

    Karel starts at Street 1, Avenue 1, facing East in a 5x5 world. What will happen after this code runs?

    move()
    putball()
    move()
    move()
    move()
    move()
    move()

    1. Karel will end on Street 1, Avenue 2

    2. Karel will end on Street 1, Avenue 7

    3. Correct Answer

      This code won’t run because of a syntax error

    4. Karel will crash into a wall

  14. Correct

    Question: 14

    What is top down design?

    1. Correct Answer

      Top down design is a way of designing your program by starting with the biggest problem and breaking it down into smaller and smaller pieces that are easier to solve.

    2. Top down design is a way that you can create designs on a computer to put on a web page

    3. Top down design is a way of designing your programs starting with the individual commands first

    4. Top down design is a way to use loops and if statements to decompose the problem

  15. Correct

    Question: 15

    How can we improve the following program?

    move()
    move()
    move()
    move()
    move()
    move()
    move()
    move()
    move()

    1. Break down this program into more functions

    2. Correct Answer

      Use a for loop to repeat the move command

    3. Use a while loop to repeat the move command

    4. Fix the indentation of this program

  16. Correct

    Question: 16

    In the following code below from the Cleanup Karel example, what is the purpose of If Statement #2?

    # This program has Karel walk down the
    # row and clean up all of the tennis balls
    # on the way.
    while front_is_clear():
    # If statement #1
    if balls_present():
    take_ball()
    move()

    # If statement #2
    if balls_present():
    take_ball()

    1. To move the last time

    2. To pick up the ball that is in the last spot

    3. Correct Answer

      To pick up the ball that is in the last spot, if there is one

    4. To take the ball from all of the positions that have a ball on them

  17. Correct

    Question: 17

    In the following code, what would be a good Postcondition to write?

    """
    Precondition: Karel is on a spot with a tennis ball facing East
    * Postcondition: ...
    """
    def get_on_top():
    turn_left()
    move()
    turn_right()

    1. Karel is on a spot with a tennis ball facing north

    2. Correct Answer

      Karel ends one spot above a tennis ball facing East.

    3. Karel is on the same position but on top of a ball.

    4. Karel is facing East.

  18. Correct

    Question: 18

    What is the purpose of using a for loop in code?

    1. To do something if a condition is true

    2. To do something while a condition is true

    3. Correct Answer

      To repeat something a fixed number of times

    4. To make programs run faster

  19. Correct

    Question: 19

    Which of the following commands is a valid Karel command?

    1. move

    2. move;

    3. Correct Answer

      move()
    4. move();

  20. Correct

    Question: 20

    What makes the following command an invalid Karel command?

    turn_Left()

    1. It should end in semicolon

    2. Correct Answer

      The L should be a lower l

    3. It should start with a capital T

    4. This command is correct

  21. Correct

    Question: 21

    Which of the following is the correct way to define a turn_right function in Karel?

    1. Correct Answer

      def turn_right():
      turn_left()
      turn_left()
      turn_left()
    2. def turn_right(): turn_right() turn_right() turn_right()

    3. def turn_right: turn_left() turn_left() turn_left()

    4. function turn_right(): turn_left() turn_left() turn_left()

  22. Correct

    Question: 22

    Why do we use functions in Karel programs?

    1. Break down our program into smaller parts

    2. Avoid repeating code

    3. Make our program more readable

    4. Correct Answer

      All of the above

  23. Correct

    Question: 23

    If Karel starts at Street 1 and Avenue 1, facing East, where will Karel be, and what direction will Karel be facing after running the following code? (Assume the world is 10x10 in size)

    move()
    turn_left()
    put_ball()
    turn_left()
    turn_left()
    turn_left()
    move()
    turn_left()

    1. Street 3, Avenue 1, Facing North

    2. Street 1, Avenue 4, Facing North

    3. Street 1, Avenue 3, Facing South

    4. Correct Answer

      Street 1, Avenue 3, Facing North

  24. Correct

    Question: 24

    Karel starts at Street 1 and Avenue 1, facing East. After calling the stair_step function twice, where will Karel be and what direction will Karel be facing? (assume this is a SuperKarel program and the world is 10x10 in size)

    def stair_step():
    move()
    turn_left()
    move()
    turn_right()

    1. Street 2, Avenue 2, Facing North

    2. Correct Answer

      Street 3, Avenue 3, Facing East

    3. Street 3, Avenue 3, Facing West

    4. Street 4, Avenue 4, Facing East

  25. Correct

    Question: 25

    In this code, how many times is the dance function called and how many times is it defined?

    def dance():
    turn_left()
    move()
    turn_left()
    turn_left()
    move()
    turn_left()

    move()
    dance()
    move()
    move()
    turn_left()
    dance()
    dance()

    1. Called 1 time, defined 1 time

    2. Called 1 time, defined 3 times

    3. Correct Answer

      Called 3 times, defined 1 time

    4. Called 3 times, defined 3 times


robot