-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemulateBrowser.py
36 lines (31 loc) · 923 Bytes
/
emulateBrowser.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
pastPages = []
futurePages = []
currentPage = 'home'
def emulateBrowser(command) :
global pastPages, futurePages, currentPage
if command == 'forward' :
if futurePages :
pastPages.append(currentPage)
currentPage = futurePages.pop()
elif command == 'back' :
if pastPages :
futurePages.append(currentPage)
currentPage = pastPages.pop()
else : # go to a new page
pastPages.append(currentPage)
currentPage = command
futurePages = []
print('viewing page: ', currentPage)
emulateBrowser('cats')
emulateBrowser('back')
emulateBrowser('forward')
emulateBrowser('forward')
emulateBrowser('google')
emulateBrowser('cheese factory')
emulateBrowser('blue cheese')
emulateBrowser('back')
emulateBrowser('back')
emulateBrowser('forward')
emulateBrowser('back')
emulateBrowser('dogs')
emulateBrowser('forward')