You should read: https://docs.python.org/3/library/calend...month_name
This example has no error checking and will fail if you enter wrong values:
This example has no error checking and will fail if you enter wrong values:
import calendar import datetime name2month = list(calendar.month_name) # name2month is a list, using later the index method: # https://docs.python.org/3/tutorial/datastructures.html#more-on-lists results = [] year = 2020 # we need also a year if using date or datetime objects month = name2month.index(input("what month is your event? April, January: ").title()) # str.title() converts the first letter into uppercase day = int(input("what day do you want?1 or 25 etc: ")) # will fail if the users does not enter a valid number time_stamp = datetime.date(year, month, day) # will fail later if the day is not on a calendar where = input("Where? ") what = input("What? ") result = {"when": time_stamp, "where": where, "what": what} results.append(result) print(results)
Output:what month is your event? April, January: April
what day do you want?1 or 25 etc: 11
Where? Somewhere
What? Looking
[{'when': datetime.date(2020, 4, 11), 'where': 'Somewhere', 'what': 'Looking'}]
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!