forked from lugnitdgp/Learn-Python
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsamplegame.py
More file actions
Latest commit
66 lines (60 loc) · 1.89 KB
/
Copy pathsamplegame.py
File metadata and controls
66 lines (60 loc) · 1.89 KB
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
58
59
60
61
62
63
64
65
# SAMPLE CODE TO ILLUTRATE THE CONCEPT OF BRANCHES AND FUNCTIONS IN PYTHON
# Users are advised to go through this piece of code and dry run it to get an understanding of function calls.
fromsysimportexit
defgold_room():
print"This room is full of gold.How much do you take?"
next=raw_input("> ")
if"0"innextor"1"innext:
how_much=int(next)
else:
dead("Man, learn to type a number.")
ifhow_much<50:
print"Nice, you're not greedy, you win!"
exit(0)
else:
dead("You greedy bastard!")
defbear_room():
print"There is a bear here."
print"The bear has a bunch of honey."
print"The fat bear is in front of another door."
print"How are you going to move the bear?"
bear_moved=False
whileTrue:
next=raw_input("> ")
ifnext=="take honey":
dead("The bear looks at you then slaps your face off.")
elifnext=="taunt bear"andnotbear_moved:
print"The bear has moved from the door. You can go through it now."
bear_moved=True
elifnext=="taunt bear"andbear_moved:
dead("The bear gets pissed off and chews your leg off.")
elifnext=="open door"andbear_moved:
gold_room()
else:
print"I got no idea what that means."
defcthulu_room():
print"Here you see the great evil Cthulu."
print"He, it, whatever stares at you and you go insane."
print"Do you flee for your life or eat your head?"
next=raw_input("> ")
if"flee"innext:
start()
elif"head"innext:
dead("Well that was tasty!")
else:
cthulu_room()
defdead(why):
printwhy, "Good job!"
exit(0)
defstart():
print"You are in a dark room."
print"There is a door to your right and left."
print"Which one do you take?"
next=raw_input("> ")
ifnext=="left":
bear_room()
elifnext=="right":
cthulu_room()
else:
dead("You stumble around the room until you starve.")
start()