guessesRemaining=12
Summary=[]
code=['1','2','3','4']
while guessesRemaining > 0:
report=[]
guess=validateInput()
guessesRemaining -= 1
if guess[0] == code[0]:
report.append("X")
if guess[1] == code[1]:
report.append("X")
if guess[2] == code[2]:
report.append("X")
if guess[3] == code[3]:
report.append("X")
tempCode=list(code)
tempGuess=list(guess)
if tempGuess[0] in tempCode:
report.append("O")
if tempGuess[1] in tempCode:
report.append("O")
if tempGuess[2] in tempCode:
report.append("O")
if tempGuess[3] in tempCode:
report.append("O")
ListCount=report.count("X")
if ListCount > 0:
del report[-ListCount:]
report2=report[0:4]
dash=["-","-","-","-"]
report2=report+dash
report3=report2[0:4]
report4="".join(report3)
guess2="".join(guess)
Summary+=[guess2,report4]
print(Summary)
validateInput() 调用了一个我没有在这里添加的函数。我试图弄清楚如何在 12 次猜测的过程中一次打印一行结果。通过三个猜测,我收到...
['4715', 'OO--', '8457', 'O---', '4658', 'O---']
当我想收到...
['4715', 'OO--']
['8457', 'O---']
['4658', 'O---']
我尝试以多种方式添加 \n ,但我不知道如何实现它。非常感谢任何和所有帮助。