forked from LKnopf/Python_precourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMastermindGame.py
More file actions
77 lines (44 loc) · 1.46 KB
/
MastermindGame.py
File metadata and controls
77 lines (44 loc) · 1.46 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
# -*- coding: utf-8 -*-
## MASTERMIND GAME by Birce
import random
Code_length = 4
Game_turncount=0
Set_of_colors = ['red','green', 'blue', 'magenta', 'yellow', 'purple', 'brown', 'orange']
Key_pegs= ['black', 'white']
DoubleRight_peg = Key_pegs[0]
ColorRight_peg= Key_pegs[1]
Color_code = random.sample(Set_of_colors, k = Code_length)
print(Set_of_colors)
print(Color_code)
Feedback = []
guess_code = []
def Master_Feedback():
for slot in range(len(Color_code)):
if guess_code[slot] == Color_code[slot]:
print(Key_pegs[0])
Feedback.append(Key_pegs[0])
elif guess_code[slot] in Color_code:
print(Key_pegs[1])
Feedback.append(Key_pegs[1])
return Feedback
def Guess_code():
for slot in range(len(Color_code)):
guess_code = []
new_guess = input('please Guess Color: ')
guess_code.append(new_guess)
print(guess_code)
return guess_code
terminal_result = [Key_pegs[0], Key_pegs[0], Key_pegs[0], Key_pegs[0]]
Guess_code()
Master_Feedback()
while Game_turncount<8:
if Feedback != terminal_result:
Guess_code()
Feedback = []
Master_Feedback()
Game_turncount += 1
elif Feedback == terminal_result:
print('Congrats. You did it!')
break
else:
print('Game Over. Please try again.')