Question

Programming language is Python: Define a function drawCircle. This function should expect a Turtle object, the...

Programming language is Python:

Define a function drawCircle. This function should expect a Turtle object, the coordinates of the circle’s center point, and the circle’s radius as arguments. The function should draw the specified circle. The algorithm should draw the circle’s circumference by turning 3 degrees and moving a given distance 120 times. Calculate the distance moved with the formula 2.0 × π × radius ÷ 120.0.

Define a function main that will draw a circle with the following parameters when the program is run:

  • X = 50
  • Y = 75
  • Radius = 100

Homework Answers

Answer #1

Please look at my code and in case of indentation issues check the screenshots.

-----------------main.py----------------

import math
import turtle


def drawCircle(turtleObj, centerX, centerY, radius):
   dist = (2.0 * math.pi * radius) / 120.0       #calculate the distance the pen should move, 120 times

   turtleObj.penup()                           #lift the pen, so pen shouldn't draw while moving
   turtleObj.goto(centerX, centerY)        #go to the center (X, Y)
   turtleObj.forward(radius)                   #then go forward by radius amount
   turtleObj.right(90)                           #move the pen 90 degrees to draw along the circumference
   turtleObj.pendown()                           #put the pen down for drawing
   for i in range(120):                       #loop 120 times
       turtleObj.forward(dist)                   #draw: line of length dist
       turtleObj.right(3)                        #move 3 degrees
   turtle.done()                                #pauses the screen to see the output

def main():
   #Testing
   X = 50
   Y = 75
   Radius = 100
   turtleObj = turtle.Turtle()               #create turtle object
   drawCircle(turtleObj, X, Y, Radius)    #draw the circle


main()

--------------Screenshots-------------------

------------------Output-----------------

---------------------------------------------------------------------------------------
Please give a thumbs up if you find this answer helpful.
If it doesn't help, please comment before giving a thumbs down.
Please Do comment if you need any clarification.
I will surely help you.

Thankyou

Know the answer?
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
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT