Chapter 6 ExercisesΒΆ

  1. There are errors in the indention in the following code. Fix it to work correctly without errors.

    Show Comments
  2. Fix the errors so it runs and returns the perimeter of a rectangle.

    Show Comments
  3. There are 2 syntax errors in the following code. Fix the errors so that it runs.

    Show Comments
  4. Fix the errors so the code runs and returns the area of a square.

    Show Comments
  5. The following code has 4 syntax errors. Fix the errors so that the code runs.

    Show Comments
  6. Change the code to take 3 parameters, a turtle, a size that tells it how far to go, and an angle it tells the turtle to turn.

    Show Comments
  7. The following code has three lines that need to be changed. Fix the code to run correctly.

    Show Comments
  8. Fix the errors so it prints "My name is John and I am 18 years old".

    Show Comments
  9. Change the square procedure below to take a size parameter and have the turtle go forward by the specified size each time.

    Show Comments
  10. Change the code so the function takes parameters for the base and height of the triangle. Then, write code to call the function and print the result.

    Show Comments
  11. Change the code below to create a function that calculates the cost of a trip. It should take the miles, milesPerGallon, and pricePerGallon as parameters and should return the cost of the trip.

    Show Comments
  12. Fix the errors in the procedure and call it.

    Show Comments
  13. Change the code below to create a function to return the number of miles you can drive. It will take as input (parameters) the tankCapacity, theAmountLeft, and the milesPerGallon.

    Show Comments
  14. Complete and change the code to be a function with 2 parameters that returns the time taken to travel and call the function

    Show Comments
  15. Create a procedure to draw a rectangle and call it. Be sure to take the width and height of the rectangle as input to the procedure.

    Show Comments
  16. Create a procedure that takes 2 parameters, a string that you get from a user input and an int. Make the procedure print the string the number of times the int parameter gives and call the procedure.

    Show Comments
  17. Create a procedure to draw a triangle and call it. Be sure to take the length of each side of the triangle as input to the procedure.

    Show Comments
  18. Create a procedure that takes 7 paramters (turtle, distance, angle, and 4 color strings) and call the procedure to draw a square in 4 different colors.

    Show Comments
  19. Write the code below to create a procedure that prints a mad lib. You can ask the user for input and then pass that input into the procedure.

    Show Comments
  20. Write a function that takes the current hour, current minute, an int to be added to the current hour, and an int to be added to the current minute, and return a string with the new hour and minute (standard 12 hour time; if minutes exceed 60, it should go to the hour) and call the function.

    Show Comments
Next Section - Exam Questions for Chapters 5 and 6