0

I have a txt file. I wrote some code to search the file for 'Monday' and provided a counter to check how many times 'Monday' is found in the file.

I would like to ask the question 'what do you want to search for?' and allow the end user to input a word. Then, the code should find out how many times their desired word appears in the file.

print('what do you want to search for?')
name = input()
count=0
f=open('/Users/z007881/Documents/days.txt','r')
findit=f.readlines()
for line in findit:
if "input" in line:
    count=count+1
print (count)
f.close()
gmds
  • 19,325
  • 4
  • 32
  • 58
Jayne
  • 29
  • 2
  • 2
    What is your question, what issues are you finding? BTW: `if name in findit:`? – AChampion Mar 28 '19 at 00:22
  • Possible duplicate of [User input and command line arguments](https://stackoverflow.com/questions/70797/user-input-and-command-line-arguments) – Jake Holzinger Mar 28 '19 at 00:57
  • Hint: where the code says `name = input()`, what do you think the `name =` part will do? Can you think of a way to use the resulting `name` in the logic later on, in order to solve the problem? Where the code says `if "input" in line:`, exactly what do you think this means? (Hint: what does it **normally** mean in Python, when we put something inside double quotes?) – Karl Knechtel Feb 05 '23 at 12:43

0 Answers0