Python Forum

Full Version: Python Automated Response System Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi there everyone. I am new to python and I just wanted to know how it would be possible to generate different responses within this code depending on what I input.

Basically what I need to happen is when I input "I Lost My License", or "Problem Saving File" into the subject of the email.

I need it to output:

Dear [email protected],
Thank you for contacting our company. You will be contacted via email
to verify your license request.
Thank you,
Company Customer Service

I also need to do this with a few other responses. Would I be doing this with if statements? Please let me know if I'm on the right track at all with my code. Any modifications would help me out a ton and help my understanding with python

Thank you :)

print()
print()

email = input("Enter your Email:")
name = input("Enter your Message Subject:")
name = input("Enter your Message Body:")

Problem_Saving_File = input ("Dear " + email + ", Thank you for contacting our company. Saving a file is done by pressing CTRL-S (Windows) or CMD-S (Mac). Thank you, Company Customer Service")

I_Lost_My_License = input (" Dear " + email + ", Thank you for contacting our company. You will be contacted via email to verify your license request. Thank you, Company Customer Service")
Any help or recommendations would be really appreciated
(Oct-08-2019, 11:11 PM)altoon Wrote: [ -> ]Basically what I need to happen is when I input "I Lost My License", or "Problem Saving File" into the subject of the email.

I need it to output:

Dear [email protected],
Thank you for contacting our company. You will be contacted via email
to verify your license request.
Thank you,
Company Customer Service

Hi!

Maybe you could use something like:

# license_01.py
#
 
email1 = input('Please, enter your email:\n')
subject1 = input('Please, enter your Message Subject:\n')
subject1 = subject1.lower()
messageBody1 = input('Please, enter your Message Body:\n')

if subject1 == 'i lost my license':
    print(f'''\nDear customer {email1},

Thank you for contacting our company. You will be contacted via email to verify your license request.

Thank you,

Company Customer Service''')
if subject1 == 'problem saving file':
    print(f'''\nDear customer {email1},

Thank you for contacting our company. Saving a file is done by pressing CTRL-S (Windows) or CMD-S (Mac).

Thank you,

Company Customer Service''')
if subject1 != 'i lost my license' and subject1 != 'problem saving file':
    print(f'Sorry, you should write, word for word, either "I lost my license" or "Problem saving file" on the message subject.')
that produces the following inputs and outputs:
Output:
Please, enter your email: [email protected] Please, enter your Message Subject: I Lost My License Please, enter your Message Body: Hello, blah blah blah ... Dear customer [email protected], Thank you for contacting our company. You will be contacted via email to verify your license request. Thank you, Company Customer Service
Output:
Please, enter your email: [email protected] Please, enter your Message Subject: Problem Saving File Please, enter your Message Body: Hello, blah blah blah ... Dear customer [email protected], Thank you for contacting our company. Saving a file is done by pressing CTRL-S (Windows) or CMD-S (Mac). Thank you, Company Customer Service
Output:
Please, enter your email: [email protected] Please, enter your Message Subject: This is a test. Please, enter your Message Body: Hello, blah blah blah ... Sorry, you should write, word for word, either "I lost my license" or "Problem saving file" on the message subject.

Nevertheless, note that on line 6:

subject1 = subject1.lower()
changes all the words in the message subject to lowercase, so it doesn't matter if the customer writes "I lost my license", "I lost My license", "I Lost My License", or other possibilities using the same exact words. The same applies to "Problem saving file". Keep in mind, though, that if the customer doesn't write those exact words, even if it is the United Kingdom's spelling 'licence' instead of the United States' spelling 'license', the program would take it as an invalid entered string in the message subject.

You could, of course, do the necessary changes to take this into consideration, or to apply it to your other possible message subjects.

All the best,
In order to save repeated typing one can use dictionaries and try...except:

email = 'somebody@somewhere'                                                           
subject = 'I lost my license'                                                          
header = (f'Dear customer {email},\n\n' 
           'Thank you for contacting our company.') 
footer = 'Thank you\n\nCompany customer service'
categories = {'i lost my license': 'You will be contacted via email to verify you license request.\n\n',
              'problem saving file': 'Saving file is done by pressing CTRL-S (Windows} or CMD- (Mac).\n\n'}

try: 
    print(f'{header}{categories[subject.lower()]}{footer}') 
except KeyError: 
    print('Sorry, dada-dada-blah-blah') 
This way one needs to add only key-value pair to categories dictionary for additional subject.