-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mastermind.py
36 lines (32 loc) · 855 Bytes
/
Mastermind.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
import random
numberOfPegs=4
numberOfGuesses=12
numberOfColors=6
ch = ""
for i in range(numberOfPegs):
ch=ch+str(random.randint(1,numberOfColors))
i = 0
while i < numberOfGuesses:
ip = input("Guess: ")
if ip == "end":
i = numberOfGuesses
else:
black = 0
white = 0
for j in range(numberOfPegs):
if ip[j]==ch[j]:
black=black+1
else:
con=True
for c in ch:
if ip[j]==c and con:
white=white+1
con=False
if black == numberOfPegs:
print("You Win")
i = numberOfGuesses
else:
print("black: " + str(black) + " white: " + str(white))
i = i + 1
if i == numberOfGuesses:
print("You Lose. The answor was " + ch + ".")