Click here to Skip to main content
15,924,367 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in my code:

C#
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:
C#
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:
C#
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.
Posted
Updated 6-Mar-16 3:52am

1 solution

Your 'not in' is wrong...You should write it like this:
Python
if user_input.split() not in [key_words, key_words1, key_words2, key_words3, key_words_4]:

Otherwise it searches only in the first list, not in the list of all the lists...
So as the keyword is in the 3rd list it will print an error message, and then proceed to the next statement...
 
Share this answer
 
Comments
kesh123 6-Mar-16 10:40am    
thanks, but its stil printing an extra error message even when the user can't input anymore, like so:
what problems are you having with your phone? s;d;lsd
Sorry,try again
sorry, our system does is not getting the problem with your phone
I would advise you to contact the service provider
where it says sorry, try again at the end, it shouldn't do that but go straight to "sorry, our system does is not getting the problem with your phone
I would advise you to contact the service provider"
and when the user input "my phone has cracked", it still prints the error message with the solution
Kornfeld Eliyahu Peter 6-Mar-16 10:43am    
Range(5) means 6! times...
Kornfeld Eliyahu Peter 6-Mar-16 12:50pm    
Ops...Remembered that it is zero based, but forgot the other part...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900