2016-12-31 3 views
-2

Mein Code:Wie kann ich fix „Valueerror: zu viele Werte entpacken (2 erwartet)“ in Python

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-resetting 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 in problems: 
     if words & keywords: 
      solution = input('Is this what the problem is?', problems) 
     else: 
      print("Sorry, I do not understand") 
     if solution == "yes": 
          print('Please follow these steps to fix your phone:') 
for number, step in enumerate(steps, 1): 

print('{}. {}'.format(number, step)) 
+1

Sie stellen sicher, dass 'problems' nur Tupel der Länge enthält zwei, oder ändern Sie die' for' Schleife, um das 3-Tupel zu erwarten, dass es tatsächlich enthält - 'für Problem, Schlüsselwörter, Lösungen zu Problemen: '. – jonrsharpe

+0

formatieren Sie bitte Ihr Beispiel. – ppasler

+1

Und dann wird es Spaß machen, die Funktionssignatur der Eingabe herauszufinden. Ihr Tipp ist, dass "Eingabe" nicht "Drucken" ist. – TigerhawkT3

Antwort

1

Jedes Element in Ihrer problems Liste besteht aus drei Elementen, so dass Ihre for-Schleife muss auspacken 3 Werte:

for problem, keywords, solutions in problems: 
    ... 
+0

danke @hiro Protagonist – vicev3nom

Verwandte Themen