You are on page 1of 3

‘’’

Marquice Page LabMM1


‘’’
from random import *
def welcome():
ask = input('''Welcome to Python Mastermind!\n
In this game, I pick four integers from [1..6] in a certain order,
and ask you to guess what they are -- in that same order!
You may guess up to ten (10) times
(Note: I may also pick the same integer multiple times!)
I will score your guess with either a black [b] or a white [w] stone
- [b] black means you have a correct digit in a correct location
- [w] white means you have a correct digit in an incorrect location
If you correctly guess my pattern before the eleventh guess, you win
Else I will have once again proven my undeniable superiority and
inevitable dominance over miserable organic life-forms. \n

So what do you say? Would you like to play a game? [y/n] \n


''')
return ask

def generateCode():
code = []
for i in range(4):
code.append(str(randint(1,6)))
print('I am thinking of a code can you guess it? ')
return code

def getList():
guess = []
b = True

while b == True:
x = input('enter four numbers: ')
print('NOTICE: if you input anything other than letters, you will loose a turn')
if len(x) != 4:
print('that is not the correct input')
else:
b = False

for i in x:
guess.append(i)
print('you guessed', guess)
return guess

def check(code,guess):
winCon = []
x=0
for i in guess:
if i == code[x]:
winCon.append('b')
elif i in code:
winCon.append('w')
else:
print(i, 'is not in the code')
x += 1
winCon.sort()
print('your result is', winCon)
return winCon

def main():
ask = welcome()
if ask == 'y':
win = False
code = generateCode()
for p in range(1,11):
guess = getList()
winCon = check(code,guess)
amt = 10 - p
print('you have',amt, 'guesses left')
if winCon == ['b','b','b','b']:
win = True
else:
winCon = False
if amt == 0:
print("You lost. you are such a noob, the answer was", code)
break
else:
amt = amt
if win == True:
print('congratulations, you have won! Good Job')
break
else:
win = False
elif ask == 'n':
print('sorry for bothering you')
else:
print('enter the right input')

main()

You might also like