麻辣家族討論版版's Archiver

twosix 發表於 2019-7-26 16:06

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]

麻辣家族討論版版為 麻辣學園 網站成員  由 昱得資訊工作室 © Since 1993 所提供