I need some help with this question relating to TurtleGraphics in Python:
A small detail of tipsy_turtle() is that when the turtle turns 90 degrees it immediately "jumps" to the new direction. This makes its movement seem jagged. It might look better if the turtle moved smoothly when turning. So, for this question, write a function called smooth_tipsy_turtle() that is the same as tipsy_turtle(), except instead of using the turtle.right(d) function, write a brand new function called smooth_right(d) that works as follows:
- If d is negative then
- repeat the following -d times:
- turn left 1 using the ordinary turtle.left command
- Otherwise, repeat the following d times:
- turn right 1 using the ordinary turtle.right command
Here is my original function to get the random turtle movement:
def tipsy_turtle(num_steps):
turtle.reset()
for step in range(num_steps):
rand_num = random.randint(-1, 1)
turtle.right(rand_num * 90)
turtle.forward(5 * random.randint(1, 3))
So, how would I go about making this work? I tried adding:
if rand_num*90 < 0:
for step in range(rand_num*90):
turtle.left(rand_num*90)
else:
turtle.right(rand_num*90)
But it didn't really work out and I don't know what I did wrong. Thanks!