Sep-03-2018, 04:31 PM
(Sep-03-2018, 02:41 PM)MTom5 Wrote: Is there a way i can condense the if/elif month statements ?
Dictionaries:
month_data = {1: {'name': 'January', 'offline': 'Password1'}, 2: {'name': 'February', 'offline': 'Password2'}, ... 12: {'name': 'December', 'offline': 'Password12'}} ... print('Month =', month_data[dt.month]['name']) if Online_Status == 1: # You don't need the parentheses. print(Online_Pass) elif Online_Status == 0: print(month_data[dt.month]['offline'])Actually, since it's indexed to integers, you could do a list of tuples:
month_data = [('', ''), ('January', 'Password1'), ('February', 'Password2'), ..., ('December', 'Password3')] ... name, offline = month_data[dt.month] print('Month =', name) if Online_Status: # You don't even need the == 1. print(Online_Pass) else: print(offline)
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures