What I am trying to do is to check whether this string is found in the text file. If it does, I want it to printout that line, else printout a message.
I have implemented this code so far:
def check_string(string):
w = raw_input("Input the English word: ")
if w in open('example.txt').read():
for w.readlines():
print line
else:
print('The translation cannot be found!')
I've tried implementing that but I got a syntax error.
It says:
invalid syntax at the line -- for w.readlines():
Any idea on how to go with this line of code?
check_stringtake an argument if it also usesraw_inputto get the word that you're looking for?grep?