Chapter 17 Exercises

  1. Fix 6 syntax errors in the code below so that the code runs correctly. It will print a story.

  2. Fix the errors so that it prints the first and last name only.

  3. Fix the 6 syntax errors in the code below so that it runs. It will print a story.

  4. Complete the code on lines 8 - 12 to initialize the variables correctly according to the order of the input.

  5. Indent 6 lines and fix the call to the procedure so that it works correctly. It will print a story.

  6. The input is a list of strings, add code below it (and fix indentation and variable names if needed) so that the code will print a story for each string in the list.

  7. Change 4 lines in the code below so that runs correctly without any errors. It will print a poem.

  8. Fix the 6 errors so that the code prints the story properly.

  9. Turn the following code into a function. It finds the name in a string and prints it. Pass in the string and return the name if it is found and “Unknown” if not. Be sure to call the function to test it. Test it both when the name is there and when it isn’t.

  10. The procedure below takes a string and splits it to create a story. Change it so that it takes multiple strings, so it creates the story without having to use split.

  11. Change the following code into a function that prints a crazy headline. It should take the values as parameters. Be sure to call the function to test it.

  12. Fix the 3 errors to make the code print out the age.

  13. Change the following into a procedure that prints the following story. Pass in the values that can change.

  14. Change the following into a procedure that takes one string in the format “name: Bob, age: 10”. The procedure should print the name and age.

  15. Write a personalized story. It should start with a string of input and split that string to get the parts it needs for the story. For example, define a name, animal, animal name, and animal adjective and create a story from that.

  16. Write a procedure that takes in a string with 2 adjectives, a noun, and a verb separated by a comma (ex: “crazy,blue,banana,runs”) in that order and prints a sentence using all 4 words.

  17. Write a procedure that prints a personalized story. It should take as input the items that will allow you to personalize a story.

  18. Write a procedure that takes in a name, age, and 2 verbs. If the age is less than 10, print a sentence using the name, age, and first verb. Otherwise print a sentence using the name, age, and second verb.

  19. Write a procedure that prints a personalized story. It should take as input the items that will allow you to personalize a story. It should also take a gender and vary the story based on the gender.

  20. Create a procedure that takes in a string like “name: Bob,age: 10,verb: dance” and prints out a sentence with just the name, age, and verb.

Next Section - Chapter 18 - Working with Data on the Web