-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path104 Challenge.py
57 lines (53 loc) · 1.67 KB
/
104 Challenge.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# myList = ["a", "b", "c", "d"]
#
# new_string = ""
# # for c in myList:
# # new_string += c + ", "
# new_string = ", ".join(myList)
#
# print(new_string)
locations = {0: "You are sitting in front of a computer learning Python",
1: "You are standing at the end of a road before a small brick building",
2: "You are at the top of a hill",
3: "You are inside a building, a well house for a small stream",
4: "You are in a valley beside a stream",
5: "You are in the forest"}
# exits = [{"Q": 0},
# {"W": 2, "E": 3, "N": 5, "S": 4, "Q": 0},
# {"N": 5, "Q": 0},
# {"W": 1, "Q": 0},
# {"N": 1, "W": 2, "Q": 0},
# {"W": 2, "S": 1, "Q": 0}]
exits = {0: {"Q": 0},
1: {"W": 2, "E": 3, "N": 5, "S": 4, "Q": 0},
2: {"N": 5, "Q": 0},
3: {"W": 1, "Q": 0},
4: {"N": 1, "W": 2, "Q": 0},
5: {"W": 2, "S": 1, "Q": 0} }
vocabulary = {
"QUIT": "Q",
"NORTH": "N",
"SOUTH": "S",
"WEST": "W"
}
loc = 1
while True:
availableExits = ", ".join(exits[loc].keys())
print(locations[loc])
if loc == 0:
break
direction = input("Available exits are " + availableExits + " ").upper()
print()
if len(direction) > 1:
# for word in vocabulary:
# if word in direction:
# direction = vocabulary[word]
words = direction.split()
for word in words:
if word in vocabulary:
direction = vocabulary[word]
break
if direction in exits[loc]:
loc = exits[loc][direction]
else:
print("You cannot go in that direction")