Question

In: Computer Science

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

Write a Python program that draw simple lollipop (a line and few circles, the line should attach to the circle, just as regular lollipop, you decide the colors),

Solutions

Expert Solution

  • To draw the lollipop in python we are using Turtle library.
  • Code:
import turtle

lollipop=turtle.Turtle() #creating turtle object
lollipop.penup()
flag=0

#below for loop to draw circle (lollipop)
#the initial radius of the circle will be 120 which will keep on decreasing by 12 after each iteration, there will be total 10 iterations.
for i in range(120, 1, -12):
        lollipop.right(90) # Face South
        lollipop.forward(i) # Move one radius
        lollipop.right(270) # Back to start heading
        lollipop.pendown() # Put the pen back down
  # choosing two random colors
        if(flag==0):
                lollipop.fillcolor('green')
                flag=1
        else:
                lollipop.fillcolor('red')
                flag=0
        lollipop.begin_fill()
        lollipop.circle(i)
        lollipop.end_fill()
        lollipop.penup() # Pen up while we go home
        lollipop.home()

#below code of snippet for lollipop stick
lollipop.right(90)
lollipop.forward(120)
lollipop.pendown()
lollipop.pensize("12")
lollipop.pencolor('black')
lollipop.forward(250)
  • And here I am attaching screenshot of the code and sample output


Related Solutions

Create a Python program file and . Your program will draw random circles with filled and...
Create a Python program file and . Your program will draw random circles with filled and non-filled color (random colors) and rectangles, fill andnon-fill color (also random colors) on the canvas. At least 10 for each category
Write a python program that will allow a user to draw by inputting commands. The program...
Write a python program that will allow a user to draw by inputting commands. The program will load all of the commands first (until it reaches command "exit" or "done"), and then create the drawing. Must include the following: change attributes: color [red | green | blue] width [value] heading [value] position [xval] [yval] drawing: draw_axes draw_tri [x1] [y1] [x2] [y2] [x3] [y3 draw_rect [x] [y] [b] [h] draw_poly [x] [y] [n] [s] draw_path [path] random random [color | width...
please answer this in a simple python code 1. Write a Python program to construct the...
please answer this in a simple python code 1. Write a Python program to construct the following pattern (with alphabets in the reverse order). It will print the following if input is 5 that is, print z one time, y two times … v five times. The maximum value of n is 26. z yy xxx wwww vvvvvv
I need to write a program in python for a restaurant. The program should let the...
I need to write a program in python for a restaurant. The program should let the user enter a meal number, then it should display the meal name, meal price, and meal calories. Also, needs the appropriate output if the user enters an invalid meal number. I am supposed to use a dictionary, but my problem is it keeps giving me an error and telling me my menu is not defined. Not sure what I am doing wrong. print ("Welcome...
Python programming: Instructions: The python program should respond to user input on a command line Below...
Python programming: Instructions: The python program should respond to user input on a command line Below are the four options - if the user input is A, the program will quit -if the user input is B, the program will display the number of times the prompt has been displayed -if the user input is C, will display whatever is stored. -if the user inputs something else, it will store that user input as a string and append it to...
Write a Python program that computes the income tax for an individual. The program should ask...
Write a Python program that computes the income tax for an individual. The program should ask the user to enter the total taxable income for the year. The program then uses the tax bracket (as shown below) to calculate the tax amount. This is based on a progressive income tax system which is how income tax is calculated in the U.S. As a result, this for example means that only income above $500,001 is taxed at 37%. Income of lower...
Write a Python program that computes the income tax for an individual. The program should ask...
Write a Python program that computes the income tax for an individual. The program should ask the user to enter the total taxable income for the year. The program then uses the tax bracket (as shown below) to calculate the tax amount. This is based on a progressive income tax system which is how income tax is calculated in the U.S. As a result, this for example means that only income above $500,001 is taxed at 37%. Income of lower...
Write a complete Python program that asks the user for a line of text (not just...
Write a complete Python program that asks the user for a line of text (not just a single word), and then tells the user whether the string is a palindrome (same forward and backward) if you ignore case and non-alphabetic characters. The following methods and functions may be useful: str.upper(), str.isalpha() -> bool, reversed(str) -> sequence, str.find(str) -> int, str.replace(str, str), str.center(int). Unless otherwise specified, they all return a string.
The Objectives are to: Use IDLE IDE for Python. Develop a few simple Python programs and...
The Objectives are to: Use IDLE IDE for Python. Develop a few simple Python programs and show they will translate and run. Experience error messages when you enter bad syntax the interpreter cannot understand. Discussion: The best way to learn Python (or any programming language) is to write & run Python programs. In this lab you will enter two programs, and run them to produce the output. Then deliberately insert syntax errors to see what kinds of error messages you...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a numeric grade (on a scale of 0-100) from the user and convert it to a letter grade based on the following table. A: 90% - 100% B 80% - 89% C 70% - 79% D 60% - 69% F <60% The program should be written so that if the user entered either a non-numeric input or a numeric input out of the 0-100 range,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT