Chapter 9 Exercises

  1. Fix 5 errors in code below to correctly print: “Rubber baby buggy bumpers.”

  2. The code currently prints the reverse of a string. Change it so that it prints the string in the correct order, but every character is separated by a space (there should even be a space between a space and the next character).

  3. Fix the indention on 3 lines below to correctly print the reverse of the string. It should print: “!yadhtriB yppaH.”

  4. Fix the errors in the code to correctly print the reverse of the string. It should print: “!gnirts a m’I ,kool yeH”

  5. Fix 4 errors in the code below to correctly print the mirror of the text in phrase. It should print: “tset a si sihTThis is a test.”

  6. The code currently prints each letter of the string twice in a row. Change it so that it prints the mirror of the string. It should print: “!rorrim a ni gnikool ekil s’tIIt’s like looking in a mirror!”

  7. The code below is supposed to replace all 1’s with i’s, but it is in an infinite loop. You can reload the page to stop the infinite loop. Add a line to make the code work. It should print: “This is a string.”

  8. Fix the errors so that the code prints “I’m just a string.”

  9. The program below is supposed to encode the text in message, but it has 5 errors. Fix the errors so that it prints: “nvvg.nv.zg.nrwmrtsg.”

  10. The code currently prints “This is a striniThis is a string”. Fix the error so that it replaces every “1” with “i” and prints “This is a string”.

  11. Rewrite the following code to create a function that takes a string and returns the reverse of the string. It should print: “!yadhtriB yppaH.”

  12. Fix the errors in the code so that it replaces the misspelled word “recieved” with the correct spelling “received”

  13. Rewrite the following code to create a function that takes a string and returns the mirror of the string. It should print: “!ssalC iHHi Class!”.

  14. Complete the code to change all the periods to commas.

  15. Modify the code below to create a function that will that will take a message and return an encoded message. It should print: “nvvg.nv.zg.nrwmrtsg.”

  16. Rewrite and fix the errors in the code to be a procedure that takes in a string and prints the reverse of the string and the mirror of the string. Make sure to call the procedure.

  17. Modify the code below to create a function decode(encoded_message) that takes the encoded message as an argument and returns the decoded string. It should return: “meet me at midnight” when called with “nvvg.nv.zg.nrwmrtsg”, and you should print this returned value.

  18. Finish the code so that it prints the mirror of the string with the correct way then the reverse. It should print: “This is a mirror!!rorrim a si sihT”

  19. Create another function that encodes a string. Pass in both the string to be encoded and the string to use to encode the string as well.

  20. Here’s the code to encode a message. Write code underneath it to decode the encoded message and print it.

Next Section - Chapter 10 - Repeating Steps with Turtles