This is a problem on Introduction to Programming 2 on Grok Learning that I am having some trouble with this so please be simple in your coding as I'm new. The problem is as follows:
Write a program that reads in a word (e.g. colour or color) and checks if it occurs in the file book.txt, printing out was found in the book. or was not found in the book..
For example, given the book.txt file:
book.txt (This is the first file provided to you by grok)
He looked out from the top of the mountain . The colour of the sky was amazing . Reds , oranges and pinks faded into a hazy blue. then your program should work like this:
Word to look for: colour colour was found in the book.
book.txt (This is the second file provided to you by Grok)
Hypothesize ? How was she going to form a hypothesis when she didn't even know what the rest of the data looked like ? then your program should work like this:
Word to look for: hypothesize hypothesize was found in the book. This is the code that I have for it as of now.
open('book.txt')
word = input('Word to look for: ')
if word in open('book.txt').read() or open('book.txt2').read():
print(word + " was found in the book.")
else:
print(word + " was not found in the book.")
- The code has troubles when the user inputs "color", even though it is not in either files but seems to have no problem with other words.