0

so im trying to simulate a walk where the user will randomly take either a step forward or backwards, hence using the probability of a coin flip. i think the program is pretty much self explanatory. i just need help debugging it because it doesn't seem to work properly yet. when i run it, the user is prompted to enter the number of steps twice, which it shouldn't, after that it does nothing but the program is still running. any help or advice is appreciated, thanks!

```
# PURPOSE: to simulate a random walk of (n) steps; steps can be taken forwards
# or backwards
#
# INPUT(S): (n) the number of steps to be taken(forward or backwards)
#
# OUTPUT(S): how many steps away from the starting point were taken
#
# EXAMPLES: input: 20; output: 6 steps away from starting point
#
#
################################################################################
import random
def randWalk(n):
n = raw_input("Enter the number of steps to be taken: ")
steps = 0
h = 0
t = 0
while (h + t ) < n:
coinFlip = random.randrange(2)
if coinFlip == 0:
h = h + 1
steps = steps + 1
else:
t = t + 1
steps = steps - 1
while (h + t) ==n:
break
return h, t, steps
def main():
n = raw_input("Enter the number of steps to be taken: ")
walk = randWalk(n)
print "You ended up", steps, "from the starting point."
main()
```