How to make python search a word in a sentence.

For students who are taking a programming course, may be restricted in what they can use, or have other unusual limitations on solving their task.

How to make python search a word in a sentence.

Postby PythonTask2301 » Tue Sep 20, 2016 10:56 am

Code: Select all
print ("=============================================")
print ("+++++++++++++++TroubleShooting+++++++++++++++")
print ("=============================================")

def problem_list ():
    screen ["smashing", "smashed", "cracked", "cracking"]
    display ["brightness", "light", "dark", "dim", "very bright", "less bright"]
    battery ["drained", "draining", "not charging"]

def user_type ():
    problem = input ("What is the issue with your mobile phone: ")
    if problem == ("smashing" or "smashed" or "cracked" or "cracking"):
         print("hadfbr")
    elif problem == ("brightness"or "light" or "dark" or "dim" or "very bright" or "less bright"):
          print("dasfhasg2")
    elif problem == ("drained" or "draining" or "not charging"):
         print("asdfgag")
    else:
        print (problem_list)
       
   
user_type() 



++++++++++++++++++++++++++++++++++++++++++++++++++++

I want to find out how to make the user type a sentence like "my phone has drained" and python searches through lists on prints out the solution.
Last edited by Yoriz on Tue Sep 20, 2016 11:57 am, edited 1 time in total.
Reason: First post lock. Added code tags.
PythonTask2301
 
Posts: 1
Joined: Tue Sep 20, 2016 10:54 am

Re: How to make python search a word in a sentence.

Postby sparkz_alot » Tue Sep 20, 2016 2:00 pm

Be aware that this forum will be closing Oct 1, 2016, so you may want to register at the new site http://python-forum.io to continue.

in your "def problem_list():" you have what I presume are three variables: screen, display and battery. If that is the case, you are not assigning the lists to the variables and this will create a fatal error. A possible means would be:
Code: Select all
 variable = list


Next, in you "def user_type():" you have:
Code: Select all
 if problem == ("smashing" or "smashed" or "cracked" or "cracking"):

You need to remove the parenthesis from your if, elif and else statements
Code: Select all
 if problem == "smashing" or "smashed" or "cracked" or "cracking":


Next, you have an "else:" statement that calls on "problem_list", yet "problem_list" returns nothing and your 3 variables are never used.

Finally, your last line of code
Code: Select all
++++++++++++++++++++++++++++++++++++++++++++++++++++

should be preceded by a '#' symbol or made part of a print statement, as you did in the beginning.

You could also relocate your 3 variables and eliminate the "def problem_list()" function entirely. This would also help you clean your if/else statements of all the "or"s
THIS FORUM WILL BE CLOSING OCT 1, 2016. PLEASE STOP BY AND REGISTER AT THE NEW LOCATION
http://python-forum.io
User avatar
sparkz_alot
 
Posts: 269
Joined: Sat Dec 06, 2014 2:55 pm
Location: US


Return to Homework

Who is online

Users browsing this forum: Bing [Bot] and 4 guests