Defining a function with 4 parameters 2 tuples with 2 elements and 2 intergers

def ChaseSimulation(G,I,t):

for i in range(50):
    
    if(i==int(G)):
      print('G', sep='', end ='')

    elif(i==int(I)):
      print('I', sep='', end ='')

    else:
      print('-', sep='', end ='')

prints the timestamp

print('X ', t,'s', sep='')

G = 0
I = 5
t = 0

while(True):

prints the line in current time

ChaseSimulation(G,I,t)

golem advances between 3-4 feet

G = G + 3 + random.random()

imp advances by 1-7 feet

I = I + 1 + 6*random.random()

increase time

t = t + 1

if imp escapes print

if(I>=50):
    print("THE IMP HAS ESCAPED TO FREEDOM AFTER {} SECONDS. MISCHIEF AND TRICKERY AWAIT!".format(t))
    break

if(G>=I):
    print("SADLY, IT’S BACK TO THE TOWER FOR THE IMP AFTER A {} SECOND-CHASE.".format(t))
    break

Instead of printing out the simulation it instead returns True (if the imp escapes) or False (if it is recaptured

  1. impSpd: A two-element tuple where element 1 is the min # feet per second and element 2 is the max # for the imp (instead of the static 1 and 7, respectively).
  2. golemSpd: A two-element tuple identical to impSpd, but gives the golem’s movement in feet per second.
  3. headStart: a single integer indicating the initial position of the imp in feet.
  4. exitPosition: A single integer indicating the foot at which the exit appears.
    chaseSimple(impSpd, golemSpd, headStart, exitPosition

Hello! Do you have any queries? This seems like an assignment. Unfortunately, we can’t give answers to assignments on the forums.

2 Likes