Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8653131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:28:10+00:00 2026-06-12T14:28:10+00:00

I am suppose to write a program using python’s turtle that creates a tree

  • 0

I am suppose to write a program using python’s turtle that creates a tree with levels. Below are some I/O’s so you see what it is suppose to do.

enter image description here

My program works for the first case, but prints too many for the second case. The stipulations for this program are:

  • must be recursive

  • can only use the following turtle functions:

    turtle.forward(100)     <-- turtle goes forward 100 steps
    turtle.right(90)        <-- turtle turns right 90 degrees
    turtle.penup()          <-- turtle lifts its pen up off of the paper
    turtle.forward(100)     <-- turtle goes forward 100 steps
    turtle.pendown()        <-- turtle puts its pen down on the paper
    turtle.pencolor("red")  <-- turtle uses red pen
    turtle.circle(100)      <-- turtle draws circle of radius 100 
    turtle.pencolor("blue") <-- turtle changes to blue pen (most other common colors work too!)
    turtle.forward(50)      <-- turtle moves forward 50 steps
    turtle.xcor()           <-- turtle returns its current x-coordinate
    turtle.ycor()           <-- turtle returns its current y-coordinate
    

My Program:

import turtle

def tree(length,n):
    """ paints a branch of a tree with 2 smaller branches, like an Y"""
    if length < (length/n):
           return       # escape the function
    turtle.forward(length)        # paint the thik branch of the tree
    turtle.left(45)          # rotate left for smaller "fork" branch
    tree(length * 0.5,length/n)      # create a smaller branch with 1/2 the lenght of the parent branch
    turtle.right(90)         # rotoate right for smaller "fork" branch
    tree(length * 0.5,length/n)      # create second smaller branch
    turtle.left(45)          # rotate back to original heading
    turtle.backward(length)       # move back to original position
    return              # leave the function, continue with calling program
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:28:12+00:00Added an answer on June 12, 2026 at 2:28 pm

    I think there are two problems.

    First, for the recursive calls, the second parameter should be n-1 instead of length/n. If you’re drawing level n, the next call will draw level n-1, not level length/n.

    The second problem is the escape condition. With the first change, the drawing will finish when there are no more levels left to draw, or n==1.

    It sounds like homework, so I won’t post the exact code,.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Visual Studio 2010 and suppose I have to write some program.
I am supposed to write a program that gets some PNG images from the
I'm trying to write a secure transfer file program using Python and AES and
I am suppose to write a program that returns the shortest distance from point
I am trying to write a python program using Python 3 I have to
Suppose I have a simple C++ program that takes in inputs and outputs some
Suppose I write a program using immutable data structures in Java. Even though it
Suppose I want to write an app for Android OS that is not going
Suppose I let the user to write a condition using Javascript, the user can
I am supposed to write program to convert infix notation to postfix notation using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.