# This program prints a "random walk" of a # character that randomly moves left or right. import random import time def main(): # initial position and number of steps to move STEPS = 20 position = 10 for i in range(STEPS): # pause for 200ms time.sleep(0.2) # randomly adjust position by -1 or +1 rnd = random.randrange(-1, 2, 2) position += rnd # print character at its current position print(" " * position, "*") main()