自学了3天,试着写了一下,不能正确判断,请各位老师指点
python3吧
全部回复
仅看楼主
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
level 1
a790a 楼主
明白了
if elif 不是顺序判断的 只判断一次
都改成if 解决了
2021年06月12日 04点06分 2
level 1
a790a 楼主
2021年06月12日 04点06分 3
level 1
a790a 楼主
2021年06月12日 05点06分 4
level 5
我希望与大家合作,开展利用手机输入法学习python编程,例如: 1 输入:j j表示:加jia汉语拼音首字母 显示:a=1;b=1;print(‘a=1,b=1\na+b=‘,a+b) I hope to cooperate with you to start learning python programming using mobile phone input methods, for example: 1 Input: j j means: add the first letter of jia Chinese pinyin Display: a=1;b=1;print(‘a=1,b=1\na+b=‘,a+b)
2021年06月14日 16点06分 5
1