2017-01-03 1 views
0

это код, программа, кажется, чтобы отобразить все проблемы и решения в одном блокеключевого слова распознавания программы не работает, поддержка была бы оценена

print("Welcome to the Apple troubleshooting program") 

query = input("Please type your problem and make sure all words are spelled correctly") 
problems = (('My phone does not turn on.', 
      {'power', 'turn', 'on', 'off'}, 
      ('Make sure the phone is fully charged.', 
       'Try hard-reseting the phone.', 
       'Buy a new battery and get it fitted by a professional.')), 
      ('My phone is freezing.', 
      {'freeze', 'freezing'}, 
      ('Clear the cache.', 
       'Free up memory by deleting unwanted apps and media.', 
       'If all fails, contact a professional.')), 
      ('The screen is cracked.', 
      {'cracked', 'crack', 'broke', 'broken', 'screen'}, 
      ('Contact your insurance company.', 
       'Purchase a new screen.', 
       'Get the screen fitted by a professional.')), 
      ('I dropped my phone in water.', 
      {'water', 'drop', 'dropped'}, 
      ('Buy a bag of rice big enough to house your phone.', 
       'Submerged the phone in the rice for 24-48 hours.', 
       'Take your phone out of the rice and it should have absorbed the moisture.'))) 


words = {''.join(filter(str.isalpha, word)) 
      for word in query.lower().split() 
for problem, keywords, solutions in problems: 
     if words and keywords: 
       print(problems) 
       answer = input("Is this what the problem is?") 
if answer == "yes": 
     print('Please follow these steps to fix your phone:') 
for number, step in enumerate(steps, 1): 
     print('{}. {}'.format(number, step)) 

ответ

1

Есть несколько вопросов, здесь.

  1. Причины ваш код отображает «все проблемы и решения в одном блоке», потому что вы print(problems) вместо print(problem) в вашем первом for цикла.

  2. В первом for цикле вы используете if заявление if words and keywords:, которая на самом деле просто тест для «truthiness» из words и keywords. Поскольку words и keywords не являются пустыми, это if утверждение всегда будет вычисляться True (если не вводить ничего для words входа), и учитывая ваш текущий код, всегда будет печатать весь problems объект, а не отдельного problem. Вместо этого, я считаю, что ваш код должен выглядеть следующим образом:

    for problem, keywords, solutions in problems: 
        # test whether any of the words from the query are "part of the problem" 
        if any(word in keywords for word in words): 
         print(problem) 
         answer = input("Is this what the problem is?") 
    
  3. Ваш отступы нуждается в пересмотре.

  4. Кроме того, вам не хватает } в вашем понимании.
+0

где отсутствует {? и он говорит, что переменная слов является недопустимым синтаксисом. – vicev3nom

+0

Вам не хватает '}', * not a * '{' в вашем понимании, в котором вы назначаете и объявляете слова. – blacksite

Смежные вопросы