Question: Don't forget comments I've given you part of a program. Only add code where I tell you to. Create a new text file and open
Don't forget comments
I've given you part of a program. Only add code where I tell you to.
Create a new text file and open it for writing. USE fout AS YOUR FILE HANDLER!
Write some color names to the file, one per line. End each line with a . There are more, but here is a sample list: yellow, gold, orange, red, maroon, violet, magenta, purple, navy, blue, skyblue, cyan, turquoise, lightgreen, green, darkgreen, chocolate, brown, black, gray, white. I recommend using between 4 and 9.
Close your file
Open your file for reading. Note: use the same variable name for handling the file here that you did earlier.
At the end of the program, close your file.
This program will read your list of colors and draw 360 line segments so that they almost make regular polygons. They will have the same number of sides as the number of colors you enter. Each line segment will be one unit longer than the previous one, and it will rotate through the colors.
PART OF PROGRAM
#Your header goes here #Import the turtle graphics stuff that we need from turtle import Turtle, Screen
# YOUR CODE GOES HERE
# DON'T MESS WITH THIS PART colors = [] #this is how you initialize a list. Next chapter!
for line in fout: #This is why you have to use fout as your file variable colors.append(line[:-1]) #Appending each color to a list
t = Turtle() #Creating a turtle drawing object
screen = Screen() #Screen to draw on screen.bgcolor('black') #background color of the screen for x in range(360): #Draw 360 line segments t.pencolor(colors[x%len(colors)]) #Change colors each time t.width(x/100 + 1) #Make the lines a little thicker as it grows t.forward(x) #Draw the segment t.left(360/len(colors) + 1) #Turn left at the corret angle to make the polygon, but add 1 degree to make it cooler # CLOSE YOUR FILE HERE
Please help me solve this
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
