-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwalking2.py
More file actions
53 lines (38 loc) · 897 Bytes
/
walking2.py
File metadata and controls
53 lines (38 loc) · 897 Bytes
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
import time
from random import randint
p = ''
pN = 0
n=""
nn=0
while True:
p = input("Input the initial position (p)")
pN = int(p)
if pN >= 10:
print('input too big, only 1~9 is valid.')
elif pN <= 0:
print('input too small, only 1~9 is valid.')
else:
break
n=input("number of iteration")
nn=int(n)
def printArr (arr) :
myStr = ''
for i in arr:
myStr = myStr + str(i)
print (myStr)
def simOneIteration (c) :
road = ['|', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '|']
road[c] = '*'
printArr(road)
while (10 > pN > 0):
simOneIteration(pN)
direction = randint(0, 1)
if direction == 0:
pN = pN + 1
else:
pN = pN - 1
for i in range(1,n):
#if (pN == 10):
#print ('He falls into a river in a cold winter!')
#elif (pN == 0):
#print ('He arrives home safely.')