Python: How to store a REQUEST for input in a variable? -
i'm building text game , need store 2 things in single variable: a string, , request input
. note don't mean store output of request - mean if variable called, both string , request itself printed, after user answers request.
raw_input("do x or y?")
therefore doesn't work me, because need store request before deploy it.
some background approach:
everything's stored in dictionary, keys user's current location , values possible choices:
dict = {location1: (location2, location3), location2: (location1, location4)...}
so, i'll print location1
, simultaneously print string
describes location, , make request input
. input triggers program print next appropriate location, , program keeps on going.
i'm trying work out recursive function this.
for each location, request input worded differently, why don't build request recursive function.
sidenote: if has other suggestions/different approaches should use instead, please share too!
for each location, request input worded differently,
simply create dictionary input request corresponding each location. ex:
requests_dict = { 'location1': 'please enter xxx: ', 'location2': 'do x or y: ', # , on }
then use dict print request.
user_input = raw_input(requests_dict['location2'])
of course, make last code based on logic 1 of dicts called, think idea.
update:
responses_dict = {} user_input = raw_input(requests_dict['location2']) responses_dict[user_input] = 'you in %s' % user_input
Comments
Post a Comment