level 1
a790a
楼主
传统猜数字游戏,四位不重复数
给出答案不能判断 是4a0b
自己看不出问题所在,青老师指导知道,多谢、
times = 0
m = set('1234567890')
n = m.copy()
a = n.pop()
b = n.pop()
c = n.pop()
d = n.pop()
print(a,b,c,d) #检测用
print('我已经准备好一个四位数字了,你来猜猜看吧')
while times<12:k=input('猜一个4位数字: ')
j=str(k)
guess = list(j)
A,B=0,0
times=times+1
if guess[0]==a:
A=A+1
elif guess[1]==b:
A=A+1
elif guess[2]==c:
A=A+1
elif guess[3]==d:
A=A+1
x=[a,b,c,d]
p=list(x+guess)
p=set(p)
B=8-len(p)
if B-A<=0:
B=0
else:B=B-A
print('猜测',times,': ',A,'A',B,'B')
if A!=4:
continue
else:
print('恭喜你只用了',times,'次就猜对了')
print('电脑给出的数是',x)
else:
print('已经12次了,还没猜到,告诉你吧'
print('电脑给出的数是',x)
2021年06月12日 04点06分
1
给出答案不能判断 是4a0b
自己看不出问题所在,青老师指导知道,多谢、
times = 0
m = set('1234567890')
n = m.copy()
a = n.pop()
b = n.pop()
c = n.pop()
d = n.pop()
print(a,b,c,d) #检测用
print('我已经准备好一个四位数字了,你来猜猜看吧')
while times<12:k=input('猜一个4位数字: ')
j=str(k)
guess = list(j)
A,B=0,0
times=times+1
if guess[0]==a:
A=A+1
elif guess[1]==b:
A=A+1
elif guess[2]==c:
A=A+1
elif guess[3]==d:
A=A+1
x=[a,b,c,d]
p=list(x+guess)
p=set(p)
B=8-len(p)
if B-A<=0:
B=0
else:B=B-A
print('猜测',times,': ',A,'A',B,'B')
if A!=4:
continue
else:
print('恭喜你只用了',times,'次就猜对了')
print('电脑给出的数是',x)
else:
print('已经12次了,还没猜到,告诉你吧'
print('电脑给出的数是',x)


