Skip to content

Instantly share code, notes, and snippets.

@jwestgard
Last active October 7, 2019 15:54
Show Gist options
  • Select an option

  • Save jwestgard/5e90f528a32420c3839e5288d74fcca9 to your computer and use it in GitHub Desktop.

Select an option

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
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