My instructions are to track a person's motion forward and backward (every step they take). Total steps are generated from 10-85, forward and backward steps max range is between 2-20. Forward steps must always be greater than backward.
So I wrote the code for this program and my colleague corrected my code. I can't seem to figure out what the else statement does? else: f= fwd?? Does it change f=f+1 to f=fwd+1? I just need a clarification on this.
For example: If the program generated the forward steps to be 4, and the backward steps to be 2, and the total number of steps to be 13, your program would display: FFFFBBFFFFBBF = 5 Steps from the start
import random
while True:
fwd= random.randint(2,20)
bkwd= random.randint(2,fwd-1)
total=random.randint(10,85)
f= 0
b = 0
t= 0
steps_taken= 0
if bkwd > fwd:
break
while total > 0:
f = 0
#Generating forward steps
while fwd > f:
if total > 0:
print("F", end="")
f=f+1
t=t+1
total=total-1
steps_taken= steps_taken+1
#I'm having trouble here
else:
f = fwd
t = t
total = total
steps_taken= steps_taken
b = 0
#Generating backward steps
while bkwd > b:
if total > 0:
print("B", end="")
t=t-1
b=b+1
total=total-1
steps_taken= steps_taken+1
else:
b = bkwd
t = t
total = total
steps_taken = steps_taken
if f > total or b > total:
break
print(" ",t, "steps from the start")
print("Forward:", f, "Backward:", b, "Total:", steps_taken )