With help from the forums (mostly @mtf) I have completed my first independent project. This project allows you to write a journal entry and also search for a word in the entries. I have only finished 1/5 of the Computer Science Career Path so I am excited to learn more and share more. Let me know if there is anything that could make this program better! Here is the link: https://www.codecademy.com/workspaces/6171bb94bd2e4c6e5b298176 Enjoy!
Just noticed that the file close is in the else clause of the if statement. It should be outside of the if but inside the for loop.
Ok, I think I fixed it…
Line 44 still looks like it has too much indentation.
You are correct. Dang, you are good! Ok, I THINK its fixed now…
Seems it is not…
omg lemme try this again
So not like this:
But like this:
wait that doesnt work
Indent should be in line with the
if (4 space indent) so that it is still inside the for loop, but not in the if statement.
I not going to say its fixed but you may check it if you want
Just give it 2 more spaces so it lines up with IF.
def search(): word = input("What is the word you are looking for? ") file_names =  for x in os.listdir(): if x.endswith(".txt"): file_names.append(x) for files in file_names: file_s = open(files, "r") read_file = file_s.read() if word in read_file: print("The word", word, "was found in", files) else: print("The word", word , "could not be found") file_s.close()
Yes. See my post above.
for name in file_names: file = open(name, "r")
If something is singular, then it should not be pluralized. The above gives the two variable names a distinct difference, but both are singular.
Ok thank you! I will make that change. I cant believe it took me that long to fix an indent. You will be correcting me forever lol
will the file = open(name, “r”) work though? Just because of the file function
file is neither a keyword nor a built-in of Python so it should work as expected.
oh, I did not know that. thanks