Question

fix this python program (error:NameError: name 'turtle' is not defined) def Drawtriangularmotion():     import turtle    ...

fix this python program (error:NameError: name 'turtle' is not defined)

def Drawtriangularmotion():

    import turtle
    import random


index=0
size=[80,75,60]
color=['red','green','blue']
myTurtle=turtle.Turtle()
screen = turtle.Screen()

def draw_square():
    global index
    myTurtle.fillcolor(color[index])
    myTurtle.begin_fill()
    for _ in range(4):

        myTurtle.left(90)
        myTurtle.forward(size[index])
    myTurtle.end_fill()
    index+=1


def draw_triangle():
    for _ in range(3):
        draw_square()
        myTurtle.penup()
        myTurtle.forward(450)
        myTurtle.left(120)
        myTurtle.pendown()

def main():
    draw_triangle()
    screen.exitonclick()

main()

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

CODE:

import turtle
import random
index=0
size=[80,75,60]
color=['red','green','blue']
myTurtle=turtle.Turtle()
screen = turtle.Screen()

def draw_square():
    global index
    myTurtle.fillcolor(color[index])
    myTurtle.begin_fill()
    for _ in range(4):

        myTurtle.left(90)
        myTurtle.forward(size[index])
    myTurtle.end_fill()
    index+=1


def draw_triangle():
    for _ in range(3):
        draw_square()
        myTurtle.penup()
        myTurtle.forward(450)
        myTurtle.left(120)
        myTurtle.pendown()

def main():
    draw_triangle()
    screen.exitonclick()

main()

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
fix this python program (error:NameError: name 'turtle' is not defined) def Drawtriangularmotion():     import turtle    ...
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
  • Answer must be in Python 3 Answer: import turtle def trifecta(size,angle,num): for i in range(num): tri(t,size)...

    Answer must be in Python 3 Answer: import turtle def trifecta(size,angle,num): for i in range(num): tri(t,size) t.right(angle) t = turtle.Turtle() s = turtle.Screen() trifecta(100,25,5) Question 11 Part b (10 points) Write a function named trifecta() that takes three parameters: 1. size 2. angle 3. num trifecta() should call tri() repeatedly so as to draw num triangles, each with sides of length size. Each triangle should be oriented angle degrees clockwise from the preceding triangle. trifecta() should create a turtle and...

  • How to make turtle in python, make the icon a turtle icon that gets gradually smaller as it goes ...

    How to make turtle in python, make the icon a turtle icon that gets gradually smaller as it goes up the screen. import turtle import math def main(): w = int(input('Width: ')) h = int(input('Height: ')) turtle.setup(w,h) # Moving turtle mTurtle = turtle.Turtle() # function call #movingTurtle(mTurtle,window) main() Part D: (movingTurtle) Give a set of instruction that sets the turtle to an actual turtle shape, and moves it form the bottom of the screen towards the top, getting smaller as...

  • Hi, can you help me add these requirements in my Turtle python program. The program is...

    Hi, can you help me add these requirements in my Turtle python program. The program is supposed to run an Olympics skating game. The program is below the requirements. Thanks Requirements -Your race will be random generated so each time there is a possibility that a different winner. -Have a countdown of “READY” “SET” “GO” appear on the screen and then the turtles take off. -Have the program tell the winner[s]. -Award Medals. -User may guess who will win. -Allow...

  • Here is a Python program. import turtle class Box:     def __init__(self, x, y, width, height):...

    Here is a Python program. import turtle class Box:     def __init__(self, x, y, width, height):         self.x = x         self.y = y         self.width = width         self.height = height     def show(self):         turtle.up()         turtle.goto(x, y)         turtle.down()         for _ in range(2):             turtle.forward(width)             turtle.right(90)             turtle.forward(height)             turtle.right(90) bigbox = Box(-100, -150, 200, 300) bigbox.show() turtle.done() If you run the above program, it will produce an error. What is the keyword that has...

  • 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...

  • Using python Here is the code import turtle def draw_triangle(vertex, length, k): ''' Draw a ...

    Using python Here is the code import turtle def draw_triangle(vertex, length, k): ''' Draw a triangle at depth k given the bottom vertex.    vertex: a tuple (x,y) that gives the coordinates of the bottom vertex. When k=0, vertex is the left bottom vertex for the outside triangle. length: the length of the original outside triangle (the biggest one). k: the depth of the input triangle. As k increases by 1, the triangles shrink to a smaller size. When k=0, the...

  • Hi I need assistance getting rid of the ugly line and this is python 3.7 Please...

    Hi I need assistance getting rid of the ugly line and this is python 3.7 Please explain how you fixed this ! File Edit Format View Help 4.1.14 in the profitPlot function in the text, fix the problem raised by reflection 4.15 Reflection: when you run this plotting program, you wil1 notice an ugly line from the origin to the first point of the plot. How can you fix this? import turtle def profitPlot(tortoise, maxPrice): for price in range(1,2 maxPrice+1):...

  • Must be done in python. This will be connected to other turtle assignments. Might need a...

    Must be done in python. This will be connected to other turtle assignments. Might need a sleep at end. Swimming in a Pond In this function, you will draw a small pond and have the turtle first take a nice walk around it and then jump in. The pond will need to be drawn in the upper left quandrant of your screen. This function needs to do the following: Contain two parameters to denote the color of the path (pen...

  • Can figure out how get my program to keep track of a total score, here is...

    Can figure out how get my program to keep track of a total score, here is my code so far in python 3.6.6 import math import random import turtle def target(): """Turtle drawing the target"""    t = turtle.Turtle() wn = turtle.Screen() wn.bgcolor("black") t.hideturtle() t.speed(0)    #most outside circle worth 10 points t.setposition(0,-275) t.color("grey") t.begin_fill() t.circle(275) t.end_fill()    #2nd most outter circle worth 20 points t.penup() t.setposition(0,-200) t.pendown() t.color("red") t.begin_fill() t.circle(200) t.end_fill()    #3rd most outter circle worth 30 points...

  • For this lab, you will create a python program locally on your machine, test it, then...

    For this lab, you will create a python program locally on your machine, test it, then upload it to this page. Create a new python file named "nightsky.py". It should begin like this:    # Lab: Night Sky import turtle import random wn = turtle.Screen() wn.title('Night Sky') t = turtle.Turtle() t.speed(0) sky_limit = 300 star_size = 25 star_angle = 144 total_stars = 50 moon_radius = 80 # TODO: steps 1 through 5 (optionally 6, and 7) wn.mainloop() We were unable...

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