0

Hey i have quite a simple problem which i haven't been able to find anywhere. Basically i need to know how to make the user input a problem and then keywords from that input will be identified. Now these keywords will be stored in a couple text files and the relevant text file must be opened e.g. key word water opens the water text file and then a series of yes or no questions presented to the user after which will eventually result in two outcomes.

I really have looked everywhere on how to do this and all code looks different or isn't what i'm looking for. Any help on any aspects of the code would be greatly appreciated.

#Task 2 Trouble-Shooter 1.0
#Zacharriah River Howells
file = open('problem1','r')
import time
print('Hello and welcome to the mobile phone Trouble-Shooter!')
time.sleep(2)
print('Please input what is wrong with your phone')

print file.read()

This is what i have so far and it works up until the last line.

Hum4n01d
  • 1,312
  • 3
  • 15
  • 30
the man
  • 3
  • 2
  • How about using the answer to [**_Multiline user input python_**](http://stackoverflow.com/questions/17016240/multiline-user-input-python) to get the user's input, and then using `line.split()` to get a list of words in each line? You can get all the words from a file with `words = file.read().split()`. – martineau Feb 24 '17 at 19:40

1 Answers1

0

Try this:

import time

print('Hello and welcome to the mobile phone Trouble-Shooter!')
time.sleep(2)

need = raw_input('Please input what is wrong with your phone ')
file = open(need,'r')
print file.read()

The raw_input function is built into Python 2 and it returns a string. Next you open the file with the name that was inputted and print out its contents.

Hum4n01d
  • 1,312
  • 3
  • 15
  • 30