Order Now  +1 678 648 4277 

Uses of function in Python Programming Assignment


For this programming challenge, you will use Turtle to draw trees and people (stick figures). Your program should contain four functions:

Tree(t, color): the function should accept a turtle object and a color (string) and draw a tree in that color. The core of the tree is an equilateral triangle (all sides are equal).

Human(t, color): the function should accept a turtle object and a color (string) and draw a human (stick figure) in that color. The function should use the circle function to draw the head of the human.

Circle(t): the function should accept a turtle object and draw a circle.

Main(): the function should prompt the user for the number of tree-human pairs he’d like to draw and their colors (hint: can store colors in lists). The program should then use the Tree and Human functions to draw the number of tree-human pairs. For each pair, a tree should be drawn first followed by a human. The ground should be drawn in green connecting all the trees and humans.

Sample Outputs: Run #1:

Sample 1

Run #2:

Sample 2
Sample 3
Sample 4

Solution:

import turtle def Tree(t,color): t.pendown() t.color(color) t.left(90) t.forward(30) t.right(90) t.forward(40) t.left(120) t.forward(80) t.left(120) t.forward(80) t.left(120) t.forward(40) t.penup() t.right(90) t.forward(30) t.left(90) def Human(t,color): t.backward(12.5) t.pendown() t.color(color) t.left(60) t.forward(25) t.left(30) t.forward(40) t.left(150) t.forward(25) t.backward(25) t.left(60) t.forward(25) t.backward(25) t.left(150) t.forward(10) t.right(90) Circle(t) t.right(90) t.forward(50) t.left(30) t.forward(25) t.penup() t.left(60) t.backward(12.5) def Circle(t): t.circle(10) def Main(): count = int(input("How many tree-human pairs do you want to draw? (1-4): ")) treeColors=[] humanColors=[] for i in range(0,count): treeColor=input("Enter the color of tree "+str(i+1)+": ") humanColor=input("Enter the color of human "+str(i+1)+": ") treeColors.append(treeColor) humanColors.append(humanColor) turtle.begin_fill() for j in range (0,count): Tree(turtle,treeColors[j]) turtle.forward(100) Human(turtle,humanColors[j]) turtle.forward(100) turtle.backward(50) turtle.color("green") turtle.pendown() turtle.backward(200*count) Main()