Chapter 13 Exercises

  1. Fix 7 problems in the code below so that it runs.

  2. Fix the errors in the code so that it prints “Less than 5” when a number is less than 5 and “Greater than or equal to 5” when it is greater than or equal to 5.

  3. Fix 6 errors in the code below so that it works correctly.

  4. Complete the code to get user input, and make choices based off the input. The input should either be “in”, “left”, or “right”; make sure the user knows that.

    Show Comments
  5. Fix the code below to assign grades correctly using elif and else. You can assume the numbers are all correct.

    Show Comments
  6. The following code prints both statements, change it so that it only prints the first one when the age is less than 6.

    Show Comments
  7. Change the code below to use elif and else rather than several ifs. Also fix it to print “Good job!” if the score is greater than 10 and less than or equal to 20 and “Amazing” if the score is over 20.

    Show Comments
  8. Complete the code so that it iterates through the list of numbers and prints positive, negative, or neither based off the integer.

    Show Comments
  9. Change the code below to use elif and else.

    Show Comments
  10. Fix the errors in the code and change it to use elif’s and else so that if the user’s score is greater than the high score, it prints “Good job!”, if it’s lower, print “Try again.”, and if it’s the same print “You tied the high score”.

  11. Change the following code to use elif and else instead.

  12. Add statements to the code, so that if the user gives a number less than 5, you ask for the input again, and have another set of decision statements based off if the number is greater than, less than, or equal to 3.

  13. Change the code below to use only 1 if, 1 elif, and 1 else.

  14. Fix the code and change the statements so there are three sets of if and else and 2 elifs.

  15. Change the code below into a procedure that takes a number as a parameter and prints the quartile. Be sure to test each quartile.

  16. Fix the code so that it prints only 1 thing for each age group and uses elif and else.

  17. Write a function that will take a number as input and return a fortune as a string. Ask the user to pick a number to get the fortune before you call the function. Have at least 5 different fortunes. Use if, elif, and else.

  18. Write a function that takes in a list of grades and returns the letter grade of the average (A is 90+, B is 80-89, C is 70-79, D is 60-69, F is 59 and below). Call the function and print the result.

  19. Write a procedure to tell an interactive story and let the user choose one of at least 3 options.

  20. Write code that iterates through number 1 - 20 and prints “Fizz” if it’s a multiple of 3, “Buzz” if it’s a multiple of 5, “FizzBuzz” if it’s a multiple of 3 and 5, and the number if it’s not a multiple of 3 or 5. It should only print one statement per number.

Next Section - Chapter 14 - Using Decisions with Turtles