Hello from Russia Sorry for my bad English. I continied Codecademy Phyton cousres, it was great! I create a little programm, check this out
from random import *
from code import *
c_list=[]
g_list=[]
tryes=3
print("Try lo unlock 4 digits code, all digits must be different")
def lock_code():
rnd_list=[0,1,2,3,4,5,6,7,8,9]
c_list=[]
i=0
for i in range(1,5):
c_list.append(rnd_list.pop( randrange(0, len(rnd_list) )))
return c_list
'''def lock_code():
c_list=[]+
c1=randrange(0,9)
c2=randrange(0,9)
while c2==c1:
c2=randrange(0,9)
c3=randrange(0,9)
while c3==c2 or c3==c1:
c3=randrange(0,9)
c4=randrange(0,9)
if c4==c3 or c4==c2 or c4==c1:
c4=randrange(0,9)
c_list.append(c1)
c_list.append(c2)
c_list.append(c3)
c_list.append(c4)
"""print("CODE list: ",c_list)"""
return c_list
'''
def guess():
g_list=[]
con = InteractiveConsole()
g1 = int(con.raw_input("Guess 1 digit: "))
g2 = int(con.raw_input("Guess 2 digit: "))
g3 = int(con.raw_input("Guess 3 digit: "))
g4 = int(con.raw_input("Guess 4 digit: "))
g_list.append(g1)
g_list.append(g2)
g_list.append(g3)
g_list.append(g4)
while g_list[0]==g_list[1] or g_list[0]==g_list[2] or g_list[0]==g_list[3] or g_list[1]==g_list[2] or g_list[1]==g_list[3] or g_list[2]==g_list[3]:
g_list=[]
print ("All digits must be different!")
g1 = int(con.raw_input("Guess 1 digit: "))
g2 = int(con.raw_input("Guess 2 digit: "))
g3 = int(con.raw_input("Guess 3 digit: "))
g4 = int(con.raw_input("Guess 4 digit: "))
g_list.append(g1)
g_list.append(g2)
g_list.append(g3)
g_list.append(g4)
"""print ("Guess list: ",g_list)"""
return g_list
def check_corr( g_list, c_list ):
if g_list==c_list:
print ("You unlock my code!!!")
return
if g_list[0]==c_list[0]:
print (g_list[0]," is CORRECT!")
elif g_list[0] in c_list:
print (g_list[0]," EXIST in code!")
else:
print (g_list[0]," is INCORRECT!")
if g_list[1]==c_list[1]:
print (g_list[1]," is CORRECT!")
elif g_list[1] in c_list:
print (g_list[1]," EXIST in code!")
else:
print (g_list[1]," is INCORRECT!")
if g_list[2]==c_list[2]:
print (g_list[2]," is CORRECT!")
elif g_list[2] in c_list:
print (g_list[2]," EXIST in code!")
else:
print (g_list[2]," is INCORRECT!")
if g_list[3]==c_list[3]:
print (g_list[3]," is CORRECT!")
elif g_list[3] in c_list:
print (g_list[3]," EXIST in code!")
else:
print (g_list[3]," is INCORRECT!")
c_list=lock_code()
g_list=guess()
while tryes!=0:
if g_list==c_list:
print ("You unlock my code!!!")
break
print("You have ",tryes," tryes left")
check_corr(g_list, c_list)
g_list=guess()
tryes-=1
if tryes==0 and g_list!=c_list:
print("You have no more tryes... Code was: ",c_list)
else:
print ("You unlock my code!!!")
```