根据您的问题,下面的程序已经过修改,还包括解决手机问题所采取的步骤。在关键字之后,步骤列表现在包含在PROBLEMS
数据库。请用您自己的步骤替换给定的步骤。提供的步骤是示例想法,但在尝试帮助某人方面也是垃圾。如果您愿意,您可以为每个解决方案添加更少或更多的步骤。
#! /usr/bin/env python3
# The following is a database of problems, keywords, and solutions.
PROBLEMS = (('My phone does not turn on.',
{'power', 'turn', 'on', 'off'},
('Smack it with a hammer.',
'Wrap your phone in duck tape.',
'Throw it into the ocean.')),
('My phone is freezing.',
{'freeze', 'freezing'},
('Dowse it in a petroleum-based product.',
'Light a match or find a suitable flame source.',
'Barbecue your phone until it is well done.')),
('The screen is cracked.',
{'cracked', 'crack', 'broke', 'broken', 'screen'},
('Find some super glue.',
'Spread the super glue over the screen of the phone.',
'Either sit on the phone or place a 100 pounds over it.')),
('I dropped my phone in water.',
{'water', 'drop', 'dropped'},
('Blow dry your phone with air below zero degrees Celsius.',
'Bake it in your oven at three hundred degrees Celsius.',
'Leave your phone on your roof for one week.')))
# These are possible answers accepted for yes/no style questions.
POSITIVE = tuple(map(str.casefold, ('yes', 'true', '1')))
NEGATIVE = tuple(map(str.casefold, ('no', 'false', '0')))
def main():
"""Find out what problem is being experienced and provide a solution."""
description = input('Please describe the problem with your phone: ')
words = {''.join(filter(str.isalpha, word))
for word in description.lower().split()}
for problem, keywords, steps in PROBLEMS:
if words & keywords:
print('This may be what you are experiencing:')
print(problem)
if get_response('Does this match your problem? '):
print('Please follow these steps to fix your phone:')
for number, step in enumerate(steps, 1):
print('{}. {}'.format(number, step))
print('After this, your phone should work.')
print('If it does not, please take it to a professional.')
break
else:
print('Sorry, but I cannot help you.')
def get_response(query):
"""Ask the user yes/no style questions and return the results."""
while True:
answer = input(query).casefold()
if answer:
if any(option.startswith(answer) for option in POSITIVE):
return True
if any(option.startswith(answer) for option in NEGATIVE):
return False
print('Please provide a positive or negative answer.')
if __name__ == '__main__':
main()