in my code:
import sys #imports sys module to use in python
key_words = ("freezing", "crashing", "restarting","apps")
key_words1=("blank", "white", "frozen", "blurry","dropped")
key_words2=("wet", "water", "soaked", "drenched", "moisture")
key_words3=("cracked", "smashed", "crack")
key_words4=("connection","wifi","cellular"
choice=("yes")
choice1=("no")
user=input("Are you having any problems with your phone?")
user=(user.lower())
if user!=choice and user !=choice1:
print("Sorry, I didn't understand that, make sure to reply with 'YES' or 'NO'.")
continue
if user==choice1:
print("that's great!")
sys.exit(0) #ends program if user's phone is working
elif user==choice:
break
user_input = input("what problems are you having with your phone? ")
user_input=(user_input.lower())
if any(i in key_words for i in user_input.split()):
print("Check for system updates")#advice for user to fix their phone
elif any(i in key_words1 for i in user_input.split()):
print("Force your phone to restart ")
elif any(i in key_words2 for i in user_input.split()):
print("1.Fill a container with rice \n 2.Put your phone inside the container for 24-48 hours until dry")
elif any(i in key_words3 for i in user_input.split()):
print("Get it replaced by yourself, a local screen-fixing shop or the supplier of your phone")
elif any(i in key_words4 for i in user_input.split())
print("restart both your router and your phone.")
Instead of having to print the advice, I have to get python to open a text file, where Python prints out solutions from it depending on the user's problem. This is my textfile:
check for system updates
Force your phone to restart
Fill a container with rice
Put your phone inside the container
Get it replaced by yourself, a local screen-fixing shop or the supplier
restart both your router and your phone
I understand how to clean and open the textile but how I want it pick solutions out dependant from what the user inputs. So if the user says" my phone has dropped", it prints out "Force your phone to restart" from the text-file I created
What I have tried:
I have tried opening my text-file, which works and readlines but I'm not sure how i would split it up so I can respond with only one of the lines from my text-file or more dependant on what the user inputs