Как я могу разделить решения для моего кода?
когда вы задаете проблему для моего кода, она говорит вам о вашей проблеме, но я не могу ее изменить, поэтому у нее есть несколько решений, она всегда дает одно и то же решение для всех различных проблем? я спрашиваю, как дать правильное решение для правильной проблемы, а не для всех проблем, приводя только к одному решению, где написано «Печать (« Решение вашей проблемы ... »). Я хотел бы изменить его, чтобы оно дает другое решение разных проблем :) заранее спасибо :))
PROBLEMS = (('My phone does not turn on.',
{'power', 'turn', 'on', 'off'}),
('My phone is freezing.',
{'freeze', 'freezing'}),
('The screen is cracked.',
{'cracked', 'crack', 'broke', 'broken', 'screen'}),
('I dropped my phone in water.',
{'water', 'drop', 'dropped'}))
POSITIVE = tuple(map(str.casefold, ('yes', 'true','yeah', 'positive','thats right', 'yeah bro','yes', '1')))
NEGATIVE = tuple(map(str.casefold, ('no', 'false','na', 'not true','thats wrong', 'na bro','nope' '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 in PROBLEMS:
if words & keywords:
print('This may be what you are experiencing:')
print(problem)
if get_response('Does this match your problem? '):
print('The solution to your problem is ...')
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()