Question

Java Turtles Drawing A Regular Polygon Write the code to have the turtle draw a regular...

Java Turtles

Drawing A Regular Polygon

Write the code to have the turtle draw a regular polygon with the specified number of sides and specified side length.

Draw the Specified number of regular polygons, each starting at the same place, however, after each polygon is drawn the turtle turns 360 / numpolys degrees

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Thanks for the question.

Below is the code you will be needing  Let me know if you have any doubts or if you need anything to change.

Thank You !!

===========================================================================

import turtle

def drawPolygon(sides,sideLength):
    myturtle = turtle.Turtle()
    canvas = turtle.Screen()

    for _ in range(sides):
        myturtle.forward(sideLength)
        myturtle.left(360//sides)

    canvas.exitonclick()


def main():

    sides=int(input('Enter the number of sides of the polygon: '))
    sideLength = float(input('Enter the length of each side: '))

    drawPolygon(sides,sideLength)

main()

Python Turtle Graphics X import turtle def drawPolygon (sides, side Length) myturtle= turtle.Turtle canvas= turtle.Screen ( i

Add a comment
Know the answer?
Add Answer to:
Java Turtles Drawing A Regular Polygon Write the code to have the turtle draw a regular...
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
  • //include comments Opts (Regular polygon) An n-sided regular polygon has n sides of the same length...

    //include comments Opts (Regular polygon) An n-sided regular polygon has n sides of the same length and all angles have the same degree (i.e., the polygon is both equilateral and equiangular). Design a class named RegularPolygon that contains: Aprivate int data field named n that defines the number of sides in the polygon with default value 3. A private double data field named side that stores the length of the side with default value 1. A private double data field...

  • Write a program that displays a convex regular polygon with m or n sides, where m...

    Write a program that displays a convex regular polygon with m or n sides, where m is the last digit of your student number plus 3, n is the second last digit plus 3. Use two buttons named “before” and “after” to change the number of sides of the polygon. Click on “before” button will show a convex regular polygon with m sides and click on “after” will show a convex regular polygon with n sides. For example, a student...

  • N-Sided Polygon An n-sided polygon is a planed figure whose sides have the same length and...

    N-Sided Polygon An n-sided polygon is a planed figure whose sides have the same length and whose angles have the same degree. Write a class called NSidedPolygon that contains the following components: Private members to store the name of a polygon, the number of sides, and the length of each side. (You are expected to select the appropriate data types for each member.) A constructor that accepts the number of sides and the length of each side. A private method...

  • Problem 2 9.9 Geometry: n-sided regular polygon pg. 362 (25 points) Follow instructions as provided on...

    Problem 2 9.9 Geometry: n-sided regular polygon pg. 362 (25 points) Follow instructions as provided on page 362, reprinted below 9.9 (Geometry: n-sided regular polygon) In an n-sided regular polygon, all sides have the same length and all angles have the same degree (i.e., the polygon is both equilateral and equiangular) Design a class named RegularPolygon that contains A private int data field named n that defines the number of sides in the polygon with default value of 3 A...

  • A regular polygon is an n-sided polygon in which all sides are of the same length...

    A regular polygon is an n-sided polygon in which all sides are of the same length and all angles have the same degree (i.e., the polygon is both equilateral and equiangular). The formula for computing the area of a regular polygon isArea =Here, s is the length of a side. Write a program that prompts the user to enter the number of sides and their length of a regular polygon and displays its area. Here is a sample run:

  • Write a program called draw_shapes.py. In your program, Create a block header with: your name the...

    Write a program called draw_shapes.py. In your program, Create a block header with: your name the date a short description of what the program does: Assignment 5: Draw shapes using turtle Import the turtle module. Create a window and screen (canvas) where your turtle will draw. Make the window 400 pixels wide x 400 pixels high and give it an indigo background and a title of "Shapes". Use this code to create a window object: # a place for the...

  • (Geometry: n-sided regular polygon) An n-sided regular polygon’s sides all have the same length and all...

    (Geometry: n-sided regular polygon) An n-sided regular polygon’s sides all have the same length and all of its angles have the same degree (i.e., the polygon is both equilateral and equiangular). Design a class named RegularPolygon that contains: ■ A private int data field named n that defines the number of sides in the polygon. ■ A private float data field named side that stores the length of the side. ■ A private float data field named x that defines...

  • Python Question Task 4 Create a function named poker_table that uses Turtle Graphics to create a...

    Python Question Task 4 Create a function named poker_table that uses Turtle Graphics to create a single poker table to accommodate all players. There should be four parameters: num_players indicates the number of players; side_length indicates the length in pixels of each side of the table; and x and y, which give the location where you should start drawing the table. The poker table should be a simple regular polygon (that is, with sides of equal length). The number of...

  • I need help with this code, I have it started here import sys import turtle menu...

    I need help with this code, I have it started here import sys import turtle menu = "Press 1 for Flower" UserChoice = input(menu) #function to draw squares def draw_square(square): for i in range(0,2): square.forward(100) square.right(70) square.forward(100) square.right(110) #function to draw flower def draw_flower(petalNumber): window = turtle.Screen() window.bgcolor("yellow") pen = turtle.Turtle() pen.shape("triangle") pen.color("red")    for number in range(0,petalNumber): draw_square(pen) pen.right(360/petalNumber) for i in range(0,4): pen.circle(20) pen.right(90)    pen.right(90) pen.forward(300) pen.right(90) draw_square(pen) pen.left(180) draw_square(pen) pen.left(270) pen.forward(200) window.exitonclick() #function for original art...

  • Draw a turtle like that in JAVA. It should not take any user input. we assign...

    Draw a turtle like that in JAVA. It should not take any user input. we assign the parameters values. 4. Create a recursive function spiral_square(size, space) that takes the length of the longest square (size) and the distance between each leg of the spiral (space) as parameters. • Hint: Think about how the parameters change at each recursive step. Should either parameter stay the same? What's the base case? • Test your functions by drawing two different squares. Now you're...

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
ADVERTISEMENT