Ask coding questions

← Back to all posts
Invalid Syntax Elif
DUN0040 (2)
In the program, it says there is an invalid syntax for an elif. I don't understand what it means.

It now says that line 42 there is an unexpected indent where it is right against the edge.

Answered by malvoliothegood (696) [earned 5 cycles]
View Answer
malvoliothegood (696)

On line 32 in your file your code is:

elif cmd == "ls" and cmd == "list":
                                for root, dirs, files in os.walk("TID/files"):
                        f or filename in files:

It should be:

if cmd == "ls" or cmd == "list":
    for root, dirs, files in os.walk("TID/files"):
          for filename in files:

Note the difference. The formatting in this file is poor. Did you copy and paste it from somewhere? You use two while loops in this file. Is there a way to break out of these loops? Finally, you need to break up this file into a series of functions, each with one purpose, then call these inside your while loops.