This repository was archived by the owner on Apr 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmastermind_cli.py
More file actions
50 lines (37 loc) · 1.33 KB
/
mastermind_cli.py
File metadata and controls
50 lines (37 loc) · 1.33 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
from random import randint
class MastermindGame:
def __init__(self):
self.colours = ["orange", "green", "purple", "red", "blue", "cyan"]
self.code = []
self.game()
def __create_code(self):
for i in range(4):
self.code.append(self.colours[int(randint(0, 3))])
def game(self):
self.__create_code()
count = 11
for i in range(10):
count -= 1
print("Tries left: %s\n" % (count))
guess_c1 = input("Guess for color 1: ")
guess_c2 = input("Guess for color 2: ")
guess_c3 = input("Guess for color 3: ")
guess_c4 = input("Guess for color 4: ")
print("")
guesses = [guess_c1, guess_c2, guess_c3, guess_c4]
rpcounter = 0
wpcounter = 0
for i in range(4):
if guesses[i] == self.code[i]:
rpcounter += 1
elif guesses[i] in self.code:
wpcounter += 1
if rpcounter >= 4:
print("ya won")
exit(0)
else:
print("Red pegs: %s, white pegs: %s\n\n" % (rpcounter, wpcounter))
print("ya failed, noob")
exit(0)
if __name__ == "__main__":
MastermindGame()