Ask coding questions

← Back to all posts
Invalid Syntax Elif
DUN0040 (2)

https://repl.it/@DUN0040/Download-Complete
In the program TID.py, 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 (268) [earned 5 cycles]
View Answer
Commentshotnewtop
malvoliothegood (268)

On line 32 in your TID.py file your code is:

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

It should be:

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

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.