Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Pyhton turtle Activity You\'ll write Turtle Graphics code to draw 3 \"block-styl

ID: 3747803 • Letter: P

Question

Pyhton turtle Activity

You'll write Turtle Graphics code to draw 3 "block-style" letters, which should be your initials (if you don't have 3 initials, you can use another letter or number.)   Here's my example of what it might look like; the letters are D P H. (Of course, it would be possible to use portions of circles or angles to make "better" letters, but that's not the point of this activity.)

Make a separate function to draw each letter (e.g., draw_h(height,color) ); the functions should accept one parameter for the height of the letter and another for the pen color; the letter width should be calculated as half the height.   I've supplied a shell of a function.

I drew my first letters 100 units tall and 50 units wide (½ the height), with 25 units between them; you should do the same. When you call your functions, you should pass 100 as the value of the parameter (e.g., draw_h(100) )    Each letter should be a different color, and you should set the pen size to something other than the default.

You can start drawing at the turtle's starting point (0,0). After you draw them 100 units tall, you should draw them a second time, passing a height of 50 to your functions.

That was the question. I just wanna know how to draw the letter with using the function and "def" in the code
one letter is enough, i will do the rest, i just wanna know how.
please help

PHo P H

Explanation / Answer

from turtle import Turtle, Screen

NAME = "IDAN"

BORDER = 1
BOX_WIDTH, BOX_HEIGHT = 60, 100 # letter bounding box

WIDTH, HEIGHT = 25,50 # letter size

def letter_A(turtle):
turtle.forward(HEIGHT / 2)
for _ in range(3):
turtle.forward(HEIGHT / 2)
turtle.right(90)
turtle.forward(WIDTH)
turtle.right(90)
turtle.forward(HEIGHT)

def letter_D(turtle):
turtle.forward(HEIGHT)
turtle.right(90)
turtle.circle(-HEIGHT / 2, 180, 30)

def letter_I(turtle):
turtle.right(90)
turtle.forward(WIDTH)
turtle.backward(WIDTH / 2)
turtle.left(90)
turtle.forward(HEIGHT)
turtle.right(90)
turtle.backward(WIDTH / 2)
turtle.forward(WIDTH)

def letter_N(turtle):
turtle.forward(HEIGHT)
turtle.goto(turtle.xcor() + WIDTH, BORDER)
turtle.forward(HEIGHT)

LETTERS = {'A': letter_A, 'D': letter_D, 'I': letter_I, 'N': letter_N}

wn = Screen()
wn.setup(800, 400) # arbitrary
wn.title("Turtle writing my name: {}".format(NAME))
wn.setworldcoordinates(0, 0, BOX_WIDTH * len(NAME), BOX_HEIGHT)

marker = Turtle()

for counter, letter in enumerate(NAME):
marker.penup()
marker.goto(counter * BOX_WIDTH + BORDER, BORDER)
marker.setheading(90)

if letter in LETTERS:
marker.pendown()
LETTERS[letter](marker)

marker.hideturtle()

wn.mainloop()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote