Hello. I am trying to figure out how to make the dictionary find the answer and find an input question. any help would be nice.
c = input("what month is your event?April, January ")
b = input("what day do you want?1 or 25 etc.")
date = c+b
date = January = {'January1': (What), 'January2': 'where'}
where = input("what is happening on January 222st")
What = input("what is happening on January 1st")
I am trying to get the 'January1':(What) to then go to What = input("what is happening on January 1st")
I have to admit that I don't understand what is the objective here. However, I just point out that on row #3 you create variable date
just to overwrite it on next line, not to mention that on row #4 you reference variable What
before it is created.
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:
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'}]