So I tried to represent a walk module by using turtle, there's a hint that said #plot pa's location on the turtle graph here if Pa_steps == 50
But mine it didn't run randomly... hmm any suggestion for the plot to appear randomly on the screen from 0,0 position with 100 walk in 50 trials?
import random
from math import hypot
import statistics
import math
from turtle import *
from random import seed, choice
# 25,75,150
# 100
# Pa
'''
Pa Walks
'''
random.seed(20190101)
def takeOnePaStep():
direction = random.randint(0,3)
if direction == 0:
return (0,1)
elif direction == 1:
return (1,0)
elif direction == 2:
return (0,-1)
elif direction == 3:
return (-1,0)
def randomWalkPa(t, Pa_steps):
x,y = 0,0
for _ in range (Pa_steps):
dx, dy = takeOnePaStep()
x += dx
y += dy
pasDist = hypot(x,y)
#plot pa's location on the turtle graph here if Pa_steps == 50
for x in range(50):
if x == 0:
t.penup()
t.goto(x,y)
t.pendown()
t.stamp()
t.forward(100)
return pasDist
def main():
t = Turtle()
# calulate_Pa(t, 100, 50)
randomWalkPa(t, 50)
exitonclick()
if __name__ == "__main__":
main()
Aucun commentaire:
Enregistrer un commentaire