简体   繁体   中英

Identifying key words from a text file

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 eg 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM