Question

2) Write a Python program that draw simple lollipop (a line and few circles, the line should atta...

2) Write a Python program that draw simple lollipop (a line and few circles, the line should attach to the circles, just as regular lollipop, you decide the colors), just as we make a "dart" for assignment. You can use the same idea when we make "target" by making few circles with different colors, and using mouse click get 2 points to draw a line.

See sample program from Zelle textbook, chapter 4, click.pyw and triangle.pyw. Or see assignment archery.pyw.

Make sure to save this program inside the folder, where the graphics.py is saved, since we need to import graphics.py on top of the program.

2 0
Add a comment Improve this question Transcribed image text
Answer #1

I am putting 4 codes here with little variations. You can use the one which suits you the best or you can edit them to meet your requirement,

[1]

import turtle
t=turtle.Turtle()
t.penup()
flag=0
#the initial radius of the circle will be 100 which will keep on decreasing by
#20 after each iteration, there will be total 5 iterations.
for i in range(100, 1, -20):
t.right(90) # Face South
t.forward(i) # Move one radius
t.right(270) # Back to start heading
t.pendown() # Put the pen back down
# choosing two random colors
if(flag==0):
t.fillcolor('pink')
flag=1
else:
t.fillcolor('red')
flag=0
t.begin_fill()
t.circle(i)
t.end_fill()
#t.circle(i) # Draw a circle
t.penup() # Pen up while we go home
t.home()


t.pendown()
t.pensize("10")
t.pencolor('blue')
t.right(90)
t.forward(250)

OUTPUT

[2]

import turtle
t=turtle.Turtle()
t.penup()
flag=0
#the initial radius of the circle will be 100 which will keep on decreasing by
#20 after each iteration, there will be total 5 iterations.
for i in range(100, 1, -20):
t.right(90) # Face South
t.forward(i) # Move one radius
t.right(270) # Back to start heading
t.pendown() # Put the pen back down
# choosing two random colors
if(flag==0):
t.fillcolor('pink')
flag=1
else:
t.fillcolor('red')
flag=0
t.begin_fill()
t.circle(i)
t.end_fill()
#t.circle(i) # Draw a circle
t.penup() # Pen up while we go home
t.home()

t.right(90)
t.forward(100)
t.pendown()
t.pensize("10")
t.pencolor('blue')

t.forward(250)

OUTPUT

[3]

import turtle
t=turtle.Turtle()
t.penup()

#array of some random colors, as we will be drawing 5 circles so i am using 5
# different colors in the array
a=["pink","purple","red","yellow","green"]
c=0
#the initial radius of the circle will be 100 which will keep on decreasing by
#20 after each iteration, there will be total 5 iterations.
for i in range(100, 1, -20):
t.right(90) # Face South
t.forward(i) # Move one radius
t.right(270) # Back to start heading
t.pendown() # Put the pen back down

#choosing colors from the array
  
t.fillcolor(a[c])
c+=1 # for next index
t.begin_fill()
t.circle(i)
t.end_fill()
#t.circle(i) # Draw a circle
t.penup() # Pen up while we go home
t.home()

t.right(90)
t.forward(100)
t.pendown()
t.pensize("10")
t.pencolor('blue')

t.forward(250)
  
OUTPUT

Add a comment
Know the answer?
Add Answer to:
2) Write a Python program that draw simple lollipop (a line and few circles, the line should atta...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT