Luis
Luis

Reputation: 1

How can I make my functions into multiple choice?

class reminder:
  

def email_alert(subject, body, to):
msg = EmailMessage()
msg.set_content(body)
msg["subject"] = subject
msg["to"] = to

user = "#######@.com"
msg["from"] = user
password = "########"

server = smtplib.SMTP_SSL("@.com", 465)

server.login(user, password)
server.send_message(msg)
server.quit()

if __name__ == '__main__':
email_alert("Rent Payment Reminder", "Hi, just a friendly reminder that your rent is due, please make a payment before the end of the month or a late charge of $50.00 will occur. Thank you, Management.", "#########@.com")

def send_sms_via_email(subject, body, to):
msg = EmailMessage()
msg.set_content(body)
msg["subject"] = subject
msg["to"] = to

user = "##########@.com"
msg["from"] = user
password = "##########"

server = smtplib.SMTP_SSL("@.com", 465)

server.login(user, password)
server.send_message(msg)
server.quit()

if __name__ == '__main__':
email_alert("Rent Payment Reminder", " Hi, just a friendly reminder that your rent is due, please make a payment before the end of the month or a late charge of $50.00 will occur. Thank you, Management.", "######@.net")

def snail_mail(s):

print("please email management @ ########@.com for regular mail reminder", s)


def invalid_selection():
print("invalid selection, please try again")

options = {"A":["Email Reminder",]email_alert, "B":["Text Reminder",send_sms_via_email], "C": 
          ["Regular Mail Reminder",snail_mail]}

for option in options:
  print(option+") "+options.get(option)[0])

choice = input("Please select a reminder: ")

val = options.get(choice)
if val is not None:
  action = val[1]
else:
  action = invalid_selection

action()

I'm trying to make my functions multiple choice. for example: Please choose a reminder: A)Email Reminder, B)Text Reminder, C)Regular Mail Reminder.

(I apologize in advance. I'm fairly new to python.)

I also tried if and else statements but could not figure out how to call the functions.

Upvotes: 0

Views: 46

Answers (1)

John Gordon
John Gordon

Reputation: 33335

options = {
    'A': 'Regular reminder',
    'B': 'Email reminder',
    'C': 'Text message reminder'
}

for letter, description in options.items():
    print(f'{letter}) {description}')

choice = input('Please choose an option: ')

if choice in options:
    print(f'You have chosen a {options[choice]}')

else:
    print(f'Unknown option {choice}')

Upvotes: 1

Related Questions