in my code:
import sys #imports sys module to use in python
key_words = ("freezing", "crashing", "restarting","apps")#key words assosciated with solutions for user to find in their problem
key_words1=("blank", "white", "frozen", "blurry","dropped")#key words assosciated with solutions for user to find in their problem
key_words2=("wet", "water", "soaked", "drenched", "moisture")#key words assosciated with solutions for user to find in their problem
key_words3=("cracked", "smashed", "crack")#key words assosciated with solutions for user to find in their problem
key_words4=("connection","wifi","cellular","data")#key words assosciated with solutions for user to find in their problem
choice=("yes")#option for user on if they're having a problem with their phone
choice1=("no")#option for user on if they're having a problem with their phone
for i in range (5):
user_input = input("what problems are you having with your phone? ")# user inputs problem they are having with their phone
user_input=(user_input.lower())#turns user's response to lowercase to find the lowercase words from the key_word's variables
if user_input.split() not in key_words or key_words1 or key_words2 or key_words3 or key_words_4:
print ("Sorry,try again")
if any(i in key_words for i in user_input.split()):#if any of the words are in user response for key_words
print (linecache.getline('solution.txt', 1))#gets line 1 from solution's notepad to respond to user with
sys.exit(0)
elif any(i in key_words1 for i in user_input.split()):#if any of the words are in user response for key_words
print (linecache.getline('solution.txt', 2))#gets line 2 from solution's notepad to respond to user with
sys.exit(0)
elif any(i in key_words2 for i in user_input.split()):#if any of the words are in user response for key_words2
print (linecache.getline('solution.txt', 3) + linecache.getline('solution.txt', 4)) #gets line 3 and 4 from solution's notepad to respond to user with
sys.exit(0)
elif any(i in key_words3 for i in user_input.split()):#if any of the words are in user response for key_words3
print (linecache.getline('solution.txt', 5))#gets line 5 and from solution's notepad to respond to user with
sys.exit(0)
elif any(i in key_words4 for i in user_input.split()):#if any of the words are in user response for key_words4
print (linecache.getline('solution.txt', 6))#gets line 6 and from solution's notepad to respond to user with
sys.exit(0)
print("sorry, our system does is not getting the problem with your phone \n I would advise you to contact the service provider")
For my code I want it to continue displaying the error message if the user's problem is not in the key_words, but after the user can't type in any more it stil displays an error message like so:
what problems are you having with your phone? lsls
Sorry,try again
what problems are you having with your phone? sdllsd
Sorry,try again
what problems are you having with your phone? sdllsd
Sorry,try again
what problems are you having with your phone? sdlld
Sorry,try again
what problems are you having with your phone? sdllsd
Sorry,try again
sorry, our system does is not getting the problem with your phone
I would advise you to contact the service provider
it tells the user to try again, after it is it's last time to enter it but it should just go straight to "sorry, our system does is not getting the problem with your phone I would advise you to contact the service provider". Also, when the user types in a correct response like "my phone is cracked", it does this:
Are you having any problems with your phone?yes
what problems are you having with your phone? my phone has cracked
Sorry,try again
Get it replaced by yourself, a local screen-fixing shop or the supplier
its suppose to just go straight to advice, not print out an error message.
What I have tried:
I have tried coding that if its not in any of the keywords it suppose to print out the error message until 5 tries, where it tells the user to go to the manufacturer.