dimanche 12 avril 2020

I am getting an invalid syntax with the else of my if statement [closed]

def main():
    t = turtle.Turtle()
    t.penup()
    random.seed(20190101)
    while who != "":
        who = input("Enter the name of who will walk (Pa, Mi-ma, Reg): ")
        if who == "Pa":
            for i in range(1, walkt):
                randomWalkpa(walkd)
            for c in pa:
                t.goto(c[0], c[1])
                t.dot(5,'black')
            padist.sort()
            print("Pa random walk of ", walkd , "steps")
            print("Mean = ", mean(padist) , "CV = ", variance(padist))
            print("Max = " , padist[-1] , "Min = " , padist[0])
        elif who == "Mi-ma":
            for i in range(1, walkt):
                randomWalkmima(walkd)
            for c in mima:
                t.goto(c[0], c[1])
                t.dot(5, 'green')
            mimadist.sort()
            print("Mi-ma random walk of ", walkd , "steps")
            print("Mean = ", mean(mimadist) , "CV = ", variance(mimadist))
            print("Max = " , (mimadist[-1] , "Min = " , mimadist[0])
        else:
            for i in range(1, walkt):
                randomWalkreg(walkd)
            for c in reg:
                t.goto(c[0], c[1])
                t.dot(5, 'red')
            regdist.sort()
            print("Reg random walk of ", walkd , "steps")
            print("Mean = ", mean(regdist) , "CV = ", variance(regdist))
            print("Max = " , regdist[-1] , "Min = " , regdist[0])
    turtle.done()

The above code is giving an invalid syntax for the "else:" but I cannot find why. I cannot find any missing or extra parenthesis. Nothing seems to be missing at all, and my indentation is correct. I've used Notepad+ to try and review my syntax as well and can't find any reason for this else: to throw a syntax error.

Note: I recognize that this seems a bit bulky and that plotting using matlib would look nicer, but I am constrained to use turtles as this is homework.

Aucun commentaire:

Enregistrer un commentaire