Professional Documents
Culture Documents
Lab mm1
Lab mm1
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()