这段代码是关于马特帕克在他的视频中问的一个问题你能解决青蛙问题吗?. 它在 Thonny 的 shell (3.7.9) 上完美运行,但在 Python IDLE Shell 3.9.4 中出现错误。有谁知道为什么会发生这种情况和/或如何解决它?
import random
def nextstesp(currstep, maxstep, stepsnum, stepslist):
#does 1 step if is not at the end, if it is it resets its position
while currstep!=maxstep:
currstep=random.randint(int(currstep)+1, maxstep)
stepsnum+=1
stepslist.append(stepsnum)
stepsnum=0
currstep=0
#initialises varibles and lists
currstep=0
maxstep=int(input('maxstep='))
stepsnum=0
stepslist=[]
#simulates the crossing many many times
for i in range(10000):
nextstesp(currstep, maxstep, stepsnum, stepslist)
#averages out the number of steps
average=sum(stepslist)/len(stepslist)
print(average)