Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“我该如何解决?”;ValueError:要解包的值太多(应为2个)";用Python_Python - Fatal编程技术网

“我该如何解决?”;ValueError:要解包的值太多(应为2个)";用Python

“我该如何解决?”;ValueError:要解包的值太多(应为2个)";用Python,python,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'}, (

我的代码:

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))

问题
列表中的每一项都由3项组成,因此for循环需要解压缩3个值:

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

确保
问题
只包含长度为2的元组,或者将
循环更改为它实际包含的3元组-
问题、关键字、问题解决方案:
。请格式化您的示例。然后,您将很高兴找到
输入
的函数签名。您的提示是,
input
不是
print
。然后您会想,为什么在确认诊断时它会打印整个问题列表。然后你会想,为什么当你给它一个无法诊断的问题时,它会说
解决方案
是未定义的。你前面还有一个漫长的发现之夜。