############################################################################### # S.L. Broschat # CptS 111 # # random_walk.py: This program uses turtle to create a random walk art # piece :). # ############################################################################### # Import modules import turtle import random def walk(color, angle, dist): ''' Changes the pen color and left-turn angle, and then moves the turtle forward. ''' turtle.color(color) turtle.left(angle) turtle.forward(dist) return def main(): ''' Asks user for number of moves, assigns turtle shape, creates lists of angles, distances, and colors, and then uses a for-loop to move the turtle. ''' num_moves = int(input('Enter number of moves: ')) turtle.shape('turtle') alist = [0, 30, 60, 90, 120, 150, 180] dlist = [10, 20, 30, 40, 50, 60] clist = ['blue', 'red', 'purple', 'green', 'yellow', 'orange',\ 'turquoise', 'magenta', 'chartreuse'] for i in range(num_moves - 1): random.shuffle(alist); random.shuffle(dlist); random.shuffle(clist) color = clist[0]; angle = alist[0]; dist = dlist[0] walk(color, angle, dist) main()