-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcarrot_in_box.py
More file actions
153 lines (130 loc) · 4.77 KB
/
carrot_in_box.py
File metadata and controls
153 lines (130 loc) · 4.77 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
"""Carrot in a Box, Alsweigart al@invent with python.com
A silly bluffing game between two human players. Based on the game
from the show 8 Out of 10 Cats.
View this code at https://nostarch.com/big-book-small-python-projects
Tags: large beginner, game, two-player"""
import random
print('''Carrot in a Box, by Al Sweigart al@inventwithpython.com
This is a bluffing game for two human players. Each player has a box.
One box has a carrot in it. To win, you must have the box with the
carrot in it.
This is a very simple and silly game.
The first player lok into their box (the second player must close
their eye during this). The first player then says "There is a carrot
in my box" or "There is not a carrot in my box". The second player then
gets to decide if theu want to swap boxes or not.
''')
input('Press Enter to begin...')
p1Name = input('Human player 1, enter your name: ')
p2Name = input('Human player2, enter your name: ')
playerNames = p1Name[:11].center(11) + ' ' + p2Name[:11].center(11)
print(''' HERE ARE TWO BOXES:
___________ ____________
/ /| / /|
*---------* | *---------* |
| RED | | | GOLD | |
| BOX | / | BOX | /
*---------* / *---------* /''')
print()
print(playerNames)
print()
print(p1Name + ', you have a RED box in front of you.')
print(p2Name + ', you have a GOLD box in front of you.')
print()
print(p1Name + ', you will get to look into your box.')
print(p2Name.upper() + ', close your eyes and don\'t look !!!')
input('When ' + p2Name + ' has closed their eyes, press Enter...')
print()
print(p1Name + ' here is the inside of your box:')
if random.randint(1, 2) == 1:
carrotInFirstBox = True
else:
carrotInFirstBox = False
if carrotInFirstBox:
print('''
___VV_____
| VV |
| VV |
|___||_____| ____________
/ || /| / /|
*----------* | *----------* |
| RED | | | GOLD | |
| BOX | / | BOX | /
*---------* / *---------* /
(carrot!)''')
print(playerNames)
else:
print('''
__________
| |
| |
|__________| ___________
/ /| / /|
*---------* | *---------* |
| RED | | | GOLD | |
| BOX | / | BOX | /
*---------* / *---------* /
(no carrot!)''')
print(playerNames)
input('Press Enter to continue...')
print('\n' * 100) # Clear the screen by printing several newlines.
print(p1Name + ', tell ' + p2Name + ' to open their eyes.')
input('Press Enter to continue...')
print()
print(p1Name + ', say one of the following sentences to ' + p2Name + '.')
print(' 1) There is a carrot in my box.')
print(' 2) There is not a carrot in my box.')
print()
input('Then press Enter to continue...')
print()
print(p2Name + ', do you want to swap boxes with ' + p1Name + '? YES/NO')
while True:
response = input('> ').upper()
if not (response.startswith('Y') or response.startswith('N')):
print(p2Name + ', please enter "YES" or "NO" .')
else:
break
firstBox = 'RED ' #note the space after the "D".
secondBox = 'GOLD'
if response.startswith('Y'):
carrotInFirstBox = not carrotInFirstBox
firstBox, secondBox = secondBox, firstBox
print('''
___________ ____________
/ /| / /|
*---------* | *---------* |
| {} | | | {} | |
| BOX | / | BOX | /
*---------* / *---------* /'''.format(firstBox, secondBox))
print(playerNames)
input('Press Enter to reveal the winner...')
print()
if carrotInFirstBox:
print('''
___VV_____ __________
| VV | | |
| VV | | |
|___||_____| |__________|
/ || /| / /|
*---------* | *---------* |
| {} | | | {} | |
| BOX | / | BOX | /
*---------* / *---------* / '''.format(firstBox, secondBox))
else:
print('''
__________ ___VV_____
| | | VV |
| | | VV |
|__________| |___||_____|
/ /| / || /|
*---------* | *---------* |
| {} | | | {} | |
| BOX | / | BOX | /
*---------* / *---------* / '''.format(firstBox, secondBox))
print(playerNames)
# This modification mad possible through the 'carrotInFirstBox' variable
if carrotInFirstBox:
print(p1Name + ' is the winner!')
else:
print(p2Name + 'is the winner!')
print('Thanks for playing!')