1

This code is about a problem Matt Parker asked on his video Can you solve The Frog Problem?. It runs perfectly on Thonny's shell (3.7.9) but gives an error in Python IDLE Shell 3.9.4. Does anyone know why this happens and/or how to solve it please?

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)

Python IDLE Shell 3.9.4 screenshot Thonny's Shell 3.7.9 screenshot

  • Hi! Would you mind adding the actual error message? Also I'd write what you've tried so far. It is also good practice on this site to find exactly where the error is - what specific command fails, and present it in a [Minimal Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example). – Andreas Storvik Strauman Apr 11 '21 at 09:50

0 Answers0