i have this code to simulated a walk going either forwards or backwards amd i need to modify it so that it can go either up, down, left or right. only problem is im stuck can you offer any advice? thanks
import random
filename="walk1.txt"
def randWalk(n):
steps = 0 #start out at 0
for x in range(n):
steps += random.choice((-1,1)) #x += 1 means x = x + 1
return steps
def main():
sum=0
n = input("Enter the number of steps to be taken: ")
file=open(filename,'w')
for x in range (100):
sum=0
result = randWalk(int(n)) #You have to convert str to int
sum=sum+result
avg=sum/100
file.write(str(result))
file.write(str(avg))
print("you ended up",result,"steps from the start")
print("the average distance you went is",avg, "steps from the start")
file.close
main()