0
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)

The validateInput() calls a function which I didn't add here. I'm trying to figure out how to print my results one line at a time throughout the course of the 12 guesses. Through three guesses I recieve...

['4715', 'OO--', '8457', 'O---', '4658', 'O---']

when I want to recieve...

['4715', 'OO--'] 
['8457', 'O---']
['4658', 'O---'] 

I've tried to add in \n in multiple ways but I can't figure out how to implement it. Any and all help is much appreciated.

Wooble
  • 87,717
  • 12
  • 108
  • 131
Bob
  • 1,344
  • 3
  • 29
  • 63

3 Answers3

1

I've tried to add in \n in multiple ways but I can't figure out how to implement it.

It will help a lot if you structure the data properly in the first place.

Summary+=[guess2,report4]

This means "append each item found in [guess2,report4], separately, to Summary".

It seems that what you meant was "treat [guess2,report4] as a single item to append to Summary". To do this, you need to use the append method of the list:

Summary.append([guess2, report4])

Now that we have a list of pairs, each of which we want to display on a separate line, it will be much easier:

for pair in Summary:
    print(pair)
Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
0

i think you require something like

In [1]: l = ['4715', 'OO--', '8457', 'O---', '4658', 'O---']

In [2]: l1 = l[::2] # makes a list ['4715', '8457', '4658']

In [3]: l2 = l[1::2] # makes ['OO--', 'O---', 'O---']

In [4]: for i in zip(l1, l2):
   ...:     print i
   ...:
('4715', 'OO--')
('8457', 'O---')
('4658', 'O---')
avasal
  • 14,350
  • 4
  • 31
  • 47
0

if Summary is only intended to be printed and not used in subsequent steps,

Summary+=[guess2,report4,'\n']

for i in Summary:
  print i,

another way would be to use one of the solutions from How do you split a list into evenly sized chunks?

Community
  • 1
  • 1
xuanji
  • 5,007
  • 2
  • 26
  • 35