So I thought that I had this figured out, I was mistaken, I’ve been using this piece of code to practice learning dictionaries, indexes, join and split methods.
Now I’m adding some vocabulary to the list of choices and I don’t see why my code doesn’t execute properly. It will just break as soon as I enter a word like ‘north’ it’s supposed to go north when north is typed.
I figure that a line might be wrong In the for loop bu even still the output just repeats lake.
Now I’m adding some vocabulary to the list of choices and I don’t see why my code doesn’t execute properly. It will just break as soon as I enter a word like ‘north’ it’s supposed to go north when north is typed.
location={ 0:'home', 1:'road', 2:'hill', 3:'building', 4:'lake', 5:'mountains', } exits=[ {'q':0}, {'w':2,'e':1,'s':4,'n':5,'q':0}, {'n':5,'e':1,'q':0}, {'w':1,'q':0}, {'w':2,'n':1,'e':3,'q':0}, {'w':2,'s':1,'q':0}, ] vocab={ 'quit':'q', 'north':'n', 'west':'w', 'east':'e', 'south':'s', } loc = 1 while True: avail_exits = ','.join(exits[loc].keys()) print(location[loc]) if loc == 0: break direction=input('what way?'+avail_exits) if len(direction)>1: for words in vocab: if words in direction: loc = vocab[words] if direction in avail_exits: loc=exits[loc][direction] else: print('almost figured it out')P.s.
I figure that a line might be wrong In the for loop bu even still the output just repeats lake.
location={ 0:'home', 1:'road', 2:'hill', 3:'building', 4:'lake', 5:'mountains', } exits=[ {'q':0}, {'w':2,'e':1,'s':4,'n':5,'q':0}, {'n':5,'e':1,'q':0}, {'w':1,'q':0}, {'w':2,'n':1,'e':3,'q':0}, {'w':2,'s':1,'q':0}, ] vocab={ 'quit':'q', 'north':'n', 'west':'w', 'east':'e', 'south':'s', } loc = 1 while True: avail_exits = ','.join(exits[loc].keys()) print(location[loc]) if loc == 0: break direction=input('what way?'+avail_exits) if len(direction)>1: for words in vocab: direction = vocab[words] if direction in avail_exits: loc=exits[loc][direction] else: print('almost figured it out')