from random import *; def print_hallway(length, position): for i in range(1, length+1): if i == position: print('P', end = ""); else: print('.', end = ""); print("") def move_princess(doors, position): temp = randrange(0,2); if position == 1: return position + 1; if position == doors: return position - 1; if temp == 0: return position - 1; else: return position + 1; def princess(number_of_doors, steps): actual_position = randrange(1, number_of_doors + 1) for i in range(steps): print_hallway(number_of_doors,actual_position); actual_position = move_princess(number_of_doors, actual_position);