A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing

anonymous

  • one year ago

Python help: A tick is a short line that is used to mark off units of distance along a line. Write a function named drawTick() that uses a turtle parameter to draw a single tick of specified length perpendicular to the initial orientation of the turtle. The function drawTick() takes two parameters: 1. a turtle, t, that is used to draw 2. an integer, tickLen, that is the length of the tick.

  • This Question is Closed
  1. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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)

  2. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    I can't seem to draw an equal set of lines.

  3. mathmate
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 1

    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!

  4. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Hey, thanks. I was over thinking this last night. Here is my output.

  5. mathmate
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 1

    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!

  6. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    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.

  7. anonymous
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 0

    Hello @mathmate , see my attached code and output, let me know what you think based on the question i posted (attached) prior to this post.

    1 Attachment
  8. mathmate
    • one year ago
    Best Response
    You've already chosen the best response.
    Medals 1

    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!

  9. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...

23

  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.