here is my approach: import turtle s = turtle.Screen() def drawTick(t, tickLen): for num in range(tickLen): if num%2 == 0: t.forward(num) t.penup() t.forward(num) t.pendown() return drawTick length=100 turt=turtle.Turtle() tick = drawTick(turt, length)
I can't seem to draw an equal set of lines.
Hints: First, make a habit of rereading the question before you even start. The reason is that in order to give the proper context, questions tend to explain a lot, but ask you to do very little. ``` Write a function named drawTick() that uses a turtle parameter to draw a single tick of specified length ``` The above is what you're required to do. |dw:1442835739158:dw| So only a SINGLE tick is required, which is perpendicular to the original orientation of the turtle, which could be vertical or horizontal. ``` ...a single tick of specified length perpendicular to the initial orientation of the turtle. ``` |dw:1442835919067:dw| To draw the tick itself, you need to turn left/right 90 degrees, move forward tickLen/2 with pen up, then turn left/right 180 degrees to draw tickLen, turn left/right 180 again to go back to the initial position and turn right/left 90 degrees to regain the original position. Hope this helps you have an idea. Programming is an iterative art, meaning that there are many ways to do the same thing, some ways are more beautiful than the others, so your imagination is needed. Iterative because most people learn by experimenting, and few (if any) do what she wanted in the first try. Programming experience is enjoyable and unfortunately addictive!
Good job! It's excellent that you made a test to make sure the function works as planned. I looked through the code, and found the following comments that may be inconspicuous when you test only one single tick. 1. Since the function was called where the tick was to be drawn, and to stay where it was before, there is no need to do forward(50) and back (at the end). 2. The program has maintained the orientation of the turtle before and after drawing the tick. However, I still find the first and last left(180) not necessary. Perhaps I missed something. 3. I suggest you test calling the function, say 5 times, moving forward 50 units between calls. This way, you would see in context whether the function has preserved the state of the turtle. Even better, try both the x- and y-axes to make sure it works for both. cheers!
Thanks again. I am maneuvering the turtle pointer based on what the question is asking me. I practicing some midterm problems. I guess this is why you do not see the need for your 1st and 2nd comment. I emailed the TA about the turtle pointer location and he said that it looks like I am following what the question is asking. I could've simply used goto(x,y) rather than left/right. Actually, for your third comment, it is partially asked in part B of the problem. Here is the attached question since I didn't want to type and make typos. I have to come up with a way that this new function will call the old function rather than writing a longer code (which is the proper use of programming). If I have question, I'll ask but if you have an idea to steer me in the right direction, that would be nice too.
Yep, the code looks good, and works well. Now the ticks will be on one side of the axis. For you practice, if you have time, 1. Since ticks are associated with axes, you can create another function called "drawAaxis" which does pendown between ticks. 2. try drawing x- and y-axes at right angles to each other using two different calls, and a left(90) between them. (draw the y-axis from top to bottom) Have fun!