Here's my code:
import math
import random
while True:
fwd= random.randint(2,20)
bkwd= random.randint(2,fwd)
total=random.randint(10,85)
f= 0
b = 0
t= 0
if bkwd > fwd:
break
while total > 0:
f = 0
while fwd > f:
if total > 0:
print("F", end="")
f=f+1
t=t+1
total=total-1
else:
f = fwd
b = 0
while bkwd > b:
if total > 0:
print("B", end="")
t=t-1
b=b+1
total=total-1
else:
b = bkwd
if f > total:
break
print(" ",t, "steps from the start")
#I need help here printing the right amount of total steps
print("Forward:", f, "Backward:", b, "Total:", )
My instructions are: A person walks a random amount of steps forward, and then a different random number of steps backwards.
The random steps are anywhere between 2 and 20 The number of steps forward is always greater than the number of steps backwards That motion of forward / backward random steps repeats itself again and again The motion is consistent (the number of forward steps stays the same throughout the motion, and the number of backwards steps stays the same throughout the motion) After making a specific amount of total steps the person is told to stop and will be a certain amount of steps forward from where they started.
The total number of steps is generated randomly and will be between 10 and 85 You are writing a program to simulate the motion taken by the person.
Display that motion and the number of steps he ends away from where he started. 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 If the program generated the forward steps to be 5, and the backward steps to be 3, and the total steps to be 16, your program would display FFFFFBBBFFFFFBBB = 4 Steps from the start