This is a lab assignment and so you will not be submitting it. However, the concepts and practice will help you on both the homework and quizzes so I encourage you to make a serious effort on it during class and consider finishing it outside of class.

I recommend making a folder for today’s lab in COURSES as you usually do.

Exercise 1

For each snippet, what would it print out to the screen? If you think there will be an error, indicate the line with the error and explain why. After you’ve made a prediction, test out the code.

This last snippet gives you a preview of the cool things that you can do with for-loops, which we’ll officially get to next time. Play around with it to see what happens!

Exercise 2

  1. Create a new file and write a program to count the number of vowels (“aeiouy”) in a user-given string. You can assume the string is all lowercase. You don’t need to use any loops to solve this problem, remember to refer to the different methods in the reading.

  2. Update your program so that instead of counting vowels, it asks the user for characters to count in a given string (could be just one, or more than one, so you will need a for-loop for this problem).

Exercise 3

Lists and strings are both sequences, though they have some differences in how you can use them. Write out all the similarities and differences that you can think of between them. Think about things like how you made new ones, how you can change them (or can’t), and how they can be used.

Exercise 4

Now that you know how to make lists of strings, you could make a list of colors or stamps that the turtles use to generate rainbows, random combinations, and other fun creations.

A particularly powerful function from the random module is choice:

import random
colors = ["red", "blue", "green", "yellow", "purple", "orange"]
random_color = random.choice(colors)

Create a program that uses 1) the random module, 2) the turtle module, and 3) a list of colors and/or shapes to generate random turtle artwork. You should reference the Turtle methods from the previous lab for this.

Extra

If you finish early, try out the end of chapter exercises.