Python猜AB數字程式簡化
各位大大好以下是我做的猜AB數字的程式碼
想請教怎麼用更簡潔的方式來寫
Ans=input()
AnsList=list(Ans)
while True:
Guess=input()
GusList=list(Guess)
A=B=0
for i in range(len(GusList)):
if GusList[i]==AnsList[i]:
A+=1
GusList[i]=""
elif GusList[i]!=AnsList[i] and GusList.count(AnsList[i])==1:
B+=1
else:
continue
if A==4:
print("%dA%dB" % (A,B))
print("You Win!")
break
else:
print("%dA%dB" % (A,B))
頁:
[1]