SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Y Daniel Lang
Chapter:
To Computers Programs And Python
Exercise:
Programming Excercises
Question:14 | ISBN:978013274719 | Edition: 6

Question

(Turtle: draw a triangle) Write a program that draws a triangle as shown in Figure 1.18c.

a triangle is drawn in (c),

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

This program helps to create a triangle using turtle.

# import turtle
import turtle

# Create a function named draw_triangle().
# This function helps to create a triangle.
def draw_triangle(size):
    for _ in range(3):
        turtle.forward(size)
        turtle.left(120)

# Create a function named main().
def main():
    turtle.speed(1)
    size = 100
    draw_triangle(size)
    turtle.hideturtle()
    turtle.done()

if __name__ == "__main__":
    main()

 

Sample output:

1 0

Discussions

Post the discussion to improve the above solution.