Sep-29-2018, 11:57 AM
(This post was last modified: Sep-29-2018, 11:58 AM by gruntfutuk.)
I'm very confused by your explanation. The phrase "I like to eat apples" contains only two words that appear in the file you mentioned, yet you want to output a message saying 'I do not understand orange, bake, and banana'. How are you deciding what to output?
Some basic commands to learn:
You need to be clear on the problem you are trying to solve, and how to solve it (as a set of tasks, rather than specifically as a python programme at first). Think how you would do it manually if breaking it down to very basic steps rather than making human leaps.
Some basic commands to learn:
- To open a file and read contents:
with open('myfile.txt') as filename: words = filename.read()
The words variable now references a string holding the contents of the file. A '\n' character will mark each line in the string.
- To get the user input:
phrase = input('Enter a phrase: ')
- To break up a phrase into distinct words, use the
split()
string method.
- To loop through words in a list of words, use a for loop, e.g.
for word in phrase_words:
You need to be clear on the problem you are trying to solve, and how to solve it (as a set of tasks, rather than specifically as a python programme at first). Think how you would do it manually if breaking it down to very basic steps rather than making human leaps.
I am trying to help you, really, even if it doesn't always seem that way