【发布时间】:2020-04-16 06:20:57
【问题描述】:
请忽略我未使用的导入!
我试图创建一个列表来查找“pa_walk”的最小值和最大值,但我只是想出如何去做,每次我尝试它都会说错误。
import random
from math import sqrt
from math import hypot
import statistics
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(steps):
pa = [0,0]
for _ in range (steps):
nextStep = takeOnePaStep()
pa[0] += nextStep[0]
pa[1] += nextStep[1]
pasDistance = hypot(pa[0],pa[1])
return pasDistance
# paMean = statistic.mean(distance)
steps = int(input("Please enter the number of steps: "))
tries = int(input("How many times should I perform the experiment? "))
for _ in range(tries):
pa_walk= randomWalkPa(steps)
print(pa_walk)
【问题讨论】:
-
你遇到了什么错误?
-
浮点对象不能被解释为整数
标签: python tuples max min minmax