Welcome to the Treehouse Community
Looking to learn something new?
Jason AndersTreehouse Moderator 145,624 Points
Trying to master Python
I'll be the first to admit that Python is not my strongest language, but I am trying to change that. It seems that "baby steps" are the way for today, however.
I feel my code should be doing what the challenge asks, but I get the error:
Got 'False' for some existing paths.
Any hints? I'm really trying to get along with Python. :)
import os def dir_contains(path, names): for name in names: if os.path.exists(name): return True else: return False
Ryan S27,275 Points
The key with this one is that the challenge is asking you to only return
True if all of the files from the list are in the directory. If even one file is non-existent, you return
In your code, you are returning a boolean in the first iteration of the loop, so the function won't ever get a chance to check anymore file names.
Also, when using
os.path.exists(), you will need the full file path to the file, not just the name itself.
Hope this helps.