Hop Right Understanding the While Loop x 0 while absx 5 r randi01 if r 0 x x1

Hop right understanding the while loop x 0 while absx

This preview shows page 21 - 39 out of 48 pages.

Hop Right
Image of page 21
Understanding the While Loop x = 0 while abs(x) < 5: r = randi(0,1) if r == 0: x = x+1 else: x = x-1 -5 -4 -3 -2 -1 0 1 2 3 4 5 The value of X is increased from 0 to 1.
Image of page 22
Understanding the While Loop x = 0 while abs(x) < 5 : r = randi(0,1) if r == 0: x = x+1 else: x = x-1 -5 -4 -3 -2 -1 0 1 2 3 4 5 abs(x) < 5 is true. Robot not at boundary. Loop continues.
Image of page 23
Understanding the While Loop x = 0 while abs(x) < 5: r = randi(0,1) if r == 0: x = x+1 else: x = x-1 -5 -4 -3 -2 -1 0 1 2 3 4 5 Assume r = 1 Coin = Tails Hop Left
Image of page 24
Understanding the While Loop x = 0 while abs(x) < 5: r = randi(0,1) if r == 0: x = x+1 else: x = x-1 -5 -4 -3 -2 -1 0 1 2 3 4 5 The value of X is decreased from 1 to 0.
Image of page 25
Understanding the While Loop x = 0 while abs(x) < 5 : r = randi(0,1) if r == 0: x = x+1 else: x = x-1 -5 -4 -3 -2 -1 0 1 2 3 4 5 abs(x) < 5 is true. Robot not at boundary. Loop continues
Image of page 26
Understanding the While Loop x = 0 while abs(x) < 5: r = randi(0,1) if r == 0: x = x+1 else: x = x-1 -5 -4 -3 -2 -1 0 1 2 3 4 5 Assume r = 0 Coin = Heads Hop Right
Image of page 27
Understanding the While Loop x = 0 while abs(x) < 5: r = randi(0,1) if r == 0: x = x+1 else: x = x-1 -5 -4 -3 -2 -1 0 1 2 3 4 5 The value of X is increased from 0 to 1.
Image of page 28
Understanding the While Loop x = 0 while abs(x) < 5 : r = randi(0,1) if r == 0: x = x+1 else: x = x-1 -5 -4 -3 -2 -1 0 1 2 3 4 5 abs(x) < 5 is true. Robot not at boundary. Loop continues
Image of page 29
Understanding the While Loop x = 0 while abs(x) < 5: r = randi(0,1) if r == 0: x = x+1 else: x = x-1 -5 -4 -3 -2 -1 0 1 2 3 4 5 Assume r = 0 Coin = Heads Hop Right
Image of page 30
Understanding the While Loop x = 0 while abs(x) < 5: r = randi(0,1) if r == 0: x = x+1 else: x = x-1 -5 -4 -3 -2 -1 0 1 2 3 4 5 The value of X is increased from 1 to 2.
Image of page 31
Understanding the While Loop x = 0 while abs(x) < 5 : r = randi(0,1) if r == 0: x = x+1 else: x = x-1 -5 -4 -3 -2 -1 0 1 2 3 4 5 abs(x) < 5 is true. Robot not at boundary. Loop continues
Image of page 32
Understanding the While Loop x = 0 while abs(x) < 5: r = randi(0,1) if r == 0: x = x+1 else: x = x-1 -5 -4 -3 -2 -1 0 1 2 3 4 5 Assume r = 0 Coin = Heads Hop Right
Image of page 33
Understanding the While Loop x = 0 while abs(x) < 5: r = randi(0,1) if r == 0: x = x+1 else: x = x-1 -5 -4 -3 -2 -1 0 1 2 3 4 5 The value of X is increased from 2 to 3.
Image of page 34
Understanding the While Loop x = 0 while abs(x) < 5 : r = randi(0,1) if r == 0: x = x+1 else: x = x-1 -5 -4 -3 -2 -1 0 1 2 3 4 5 abs(x) < 5 is true. Robot not at boundary. Loop continues
Image of page 35
Understanding the While Loop x = 0 while abs(x) < 5: r = randi(0,1) if r == 0: x = x+1 else: x = x-1 -5 -4 -3 -2 -1 0 1 2 3 4 5 Assume r = 1 Coin = Tails Hop Left
Image of page 36
Understanding the While Loop x = 0 while abs(x) < 5: r = randi(0,1) if r == 0: x = x+1 else: x = x-1 -5 -4 -3 -2 -1 0 1 2 3 4 5 The value of X is decreased from 3 to 2.
Image of page 37
Understanding the While Loop x = 0 while abs(x) < 5 :
Image of page 38
Image of page 39

You've reached the end of your free preview.

Want to read all 48 pages?

  • Fall '19
  • Control flow

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture