Skip to content

Commit 7feb74b

Browse files
author
Charlotte Weaver
committed
Solution to lesson 4
1 parent 3442bda commit 7feb74b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
wanderer_x = 0
3+
wanderer_y = 0
4+
treasure_x = 5
5+
treasure_y = 1
6+
while True:
7+
direction = raw_input("Which direction would you like to travel in? (N, S, E, or W. done to quit)")
8+
if direction == 'E':
9+
wanderer_x += 1
10+
elif direction == 'W':
11+
wanderer_x -= 1
12+
elif direction == 'N':
13+
wanderer_y += 1
14+
elif direction == 'S':
15+
wanderer_y -= 1
16+
elif direction == 'done':
17+
break
18+
if (wanderer_y == treasure_y and wanderer_x == treasure_x):
19+
print "Congrats you found a gold necklace!"
20+
break
21+
print "You walked to x: " + str(wanderer_x) + " y: " + str(wanderer_y)

0 commit comments

Comments
 (0)