from random import randint
while 1:
r = randint(1234,9876)
time=0
# print(r) 亂數產生不重複4位數
if int(r)%10 != int(r/10)%10:
if int(r)%10 != int(r/100)%10:
if int(r)%10 != int(r/1000)%10:
if int(r/10)%10 != int(r/100)%10:
if int(r/10)%10 != int(r/1000)%10:
if int(r/100)%10 != int(r/1000)%10:
break
else:
continue
else:
continue
else:
continue
else:
continue
else:
continue
else:
continue
while 1:
g = input("請輸入猜測的不重複4位數字:")
guess = int(g)
if guess == r:
time = time + 1
print("4A0B,你答對了","共猜",time,"次")
break
else:
#判斷幾A幾B
a=0
b=0
time = time + 1
for i in range(4):
if int(r/10**i)%10 == int(guess/10**i)%10:
a=a+1
for i in range(4):
for j in range(4):
if i == j:
pass
else:
if int(r/10**i)%10 == int(guess/10**j)%10:
b = b + 1
print(a,"A",b,"B","你己猜",time,"次")
continue
print("Game over")
0 意見:
張貼留言