'''lecture08_find_bug3.py Oliver W. Layton CS151: Computational Thinking: Visual Media Spring 2021 Find the 4 bugs below ''' import turtle import random def goto(x, y): '''This function is fine!''' turtle.up() turtle.goto(x, y) turtle.down() def drawLine(color, drawThickLine=False): '''Draws a thick or thin line at a random place on the canvas ''' turtle.color(color) # turtle color not set based on color parameter: Bug 3 # if drawThickLine: is the same as checking: # if drawThickLine == True: if drawThickLine: turtle.width(8) x = random.randint(-200, 200) y = random.randint(-200, 200) goto(x, y) turtle.forward(100) turtle.width(1) turtle.color('black') def main(numLines): '''Draws a thick line 50% of the time and thin line 50% of the time at a random location on the canvas ''' for i in range(numLines): # loop thru numLines times, not just always 10 doIdrawThickLine = False if random.random() < 0.5: # doIdrawThickLine = True drawLine('red', drawThickLine=True) else: drawLine('red') # doIdrawThickLine = False # Bug 2: doIdrawThickLine not defined if we dont get into if statement # drawLine('red') # Bug 1 # drawLine('red', drawThickLine=doIdrawThickLine) # drawLine('red') # Main code if __name__ == '__main__': numLines = 100 main(numLines) turtle.exitonclick()