Last active
October 7, 2019 15:54
-
-
Save jwestgard/5e90f528a32420c3839e5288d74fcca9 to your computer and use it in GitHub Desktop.
An example of a simple class that initializes a "day" with a method to provide a greeting appropriate to the day
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Weekday(): | |
| def __init__(self, code): | |
| if code == 'mo': | |
| self.weekday = 'Monday' | |
| elif code == 'tu': | |
| self.weekday = 'Tuesday' | |
| elif code == 'we': | |
| self.weekday = 'Wednesday' | |
| elif code == 'th': | |
| self.weekday = 'Thursday' | |
| elif code == 'fr': | |
| self.weekday = 'Friday' | |
| elif code == 'sa': | |
| self.weekday = 'Saturday' | |
| elif code == 'su': | |
| self.weekday = 'Sunday' | |
| def greeting(self): | |
| return f'Happy {self.weekday}!' | |
| if __name__ == '__main__': | |
| user_input = input("Enter a day: ") | |
| today = Weekday(user_input) | |
| print(today.greeting()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment