forked from seeditsolution/pythonprogram
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMastermind Game
More file actions
56 lines (39 loc) · 926 Bytes
/
Copy pathMastermind Game
File metadata and controls
56 lines (39 loc) · 926 Bytes
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
import random
# generates a four-digit code
def gen_code():
set_code = []
for i in range(4):
val = random.randint(0, 9)
set_code.append(val)
return set_code
# asks for input from the user
def input_code():
code = input("Enter your four digit guess code: ")
return code
# plays the game
def mastermind():
genCode = gen_code()
i = 0
while i < 10:
result = ""
inputCode = [int(c) for c in input_code()]
if len(inputCode) != 4:
print("Enter only 4 digit number")
continue
if inputCode == genCode:
print("You guessed it !", genCode)
break
for element in inputCode:
if element in genCode:
if inputCode.index(element) == genCode.index(element):
result+="R"
else:
result+="Y"
else:
result+="B"
print(result)
i += 1
else:
print("You ran out of trys !", genCode)
# Driver Code
mastermind()