python 3.x - In a while loop changeing "<" to "<= " in the same code draws a different turtle graphic -
question using while loops.
i notice if use "<" condition in while loop draw different picture if use "<=" condition same code.
below see 2 different code sets , associated pictures render reference.
any or feed appreciated!
for given code use while loop start draw circle squares:
import turtle def draw_square(some_turtle): count =0 while count <4 : some_turtle.forward(100) some_turtle.right(90) count += 1 def draw_circle(): win = turtle.screen() win.bgcolor("red") nic = turtle.turtle() nic.shape("turtle") nic.color("blue") nic.speed(2) count = 0 while count <4: draw_square(nic) nic.right(10) count += 1 win.exitonclick() draw_circle() draw_square("1")
it renders following image:
i change < <= such:
import turtle
def draw_square(some_turtle): count =0 while count <=4 : some_turtle.forward(100) some_turtle.right(90) count += 1 def draw_circle(): win = turtle.screen() win.bgcolor("red") nic = turtle.turtle() nic.shape("turtle") nic.color("blue") nic.speed(2) count = 0 while count <=4: draw_square(nic) nic.right(10) count += 1 win.exitonclick() draw_circle() draw_square("1")
and following rendered:
why changing <= < in while loop have such impact on drawing?
it has position of turtle after square has been drawn. difference in draw_square function.
for first example:
while count <4 : some_turtle.forward(100) some_turtle.right(90) count += 1
the turtle stops in upper left hand corner of square so:
if second example change "<" "<=" turtle stops in upper right hand corner because it's including forth loop such:
this in-turn changes point in turtle pivots make next square fundamentally changing picture whole.
Comments
Post a Comment