Python Forum
dictionaries becoming inputs
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
dictionaries becoming inputs
#1
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")
Reply
#2
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.
buran likes this post
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
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'}]
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020