when you give a problem to my code it tells you your problem but i cant change it so it has multiple solutions it always gives the same solution to all the different problems ?
Based on your question, the program down below has been modified to also include steps that can be taken to resolve problems found with a cell phone. Following the keywords, a list of steps in now included in the PROBLEMS
database. Please substitute your own steps for those given. The provided steps are sample ideas but also junk in terms of trying to help someone. You may add a smaller or larger number of steps per solution if you so desire.
#! /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()