I have a project to do for my CMPT 120 Class. And it's using basic python coding.
I'm trying to write my name out with block letters. 'JAX'
I need to use for loops
and i'm stuck on my X
here's the code for it

``````def x(n):
t3=turtle.Pen()

t3.left(60)

t3.forward(n)
t3.left(60)
t3.forward(n)
t3.right(120)
t3.forward(n)
t3.right(60)
t3.forward(n/2)
t3.left(120)
t3.forward(n/2)
t3.right(60)
t3.forward(n)

t3.right(120)

t3.forward(n)
t3.left(60)
t3.forward(n)
t3.right(120)
t3.forward(n)
t3.right(60)
t3.forward(n/2)
t3.left(120)
t3.forward(n/2)
t3.right(60)
t3.forward(n)``````

I've separated it in parts that are similar which i can loop, but there is the
t3.right(120)
that's odd in the loop, is there a way i can still use a for loop?
thanks
ha, i need help asap, project is due tomorrow.
Thanks
Jackie

## All 3 Replies

I'm confused as to what you are trying to do.

Can you explain it again using pseudo code?

e.g.

perform this loop 10 times
action1
action2
end loop

I'm confused as to what you are trying to do.

Can you explain it again using pseudo code?

e.g.

``````perform this loop 10 times
action1
action2
end loop``````

This would be one way to shorten your code with a for loop:

``````import turtle
import time

def x(n):
"draw a turtle x of size n, shortened version using a for loop"
t3=turtle.Pen()

for k in (1, 2):
if k == 1:
t3.left(60)
else:
t3.right(120)

t3.forward(n)
t3.left(60)
t3.forward(n)
t3.right(120)
t3.forward(n)
t3.right(60)
t3.forward(n/2)
t3.left(120)
t3.forward(n/2)
t3.right(60)
t3.forward(n)

x(30)
time.sleep(3)  # show test for some seconds (just for test)``````

Nice project!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.