1

I am trying to print results on the same line for a card game, here is the desired output I want:

desired output

Here is what I get:

actual ouput

Here is my code:

  for List in tableau:
        print
        print ("Row", Row, ":", end="")
        print
        Row += 1
        for x in List:
            print (x, end="")

I'm using Python 3, thanks.

Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
Goose
  • 2,130
  • 10
  • 32
  • 43
  • possible duplicate of [Overriding the newline generation behaviour of Python's print statement](http://stackoverflow.com/questions/1677424/overriding-the-newline-generation-behaviour-of-pythons-print-statement) – Adam Liss Nov 11 '12 at 05:42

3 Answers3

3

You need to call print as a function in Python 3:

for List in tableau:
      print()  # Right here
      print ("Row", Row, ":", end="")

      Row += 1
      for x in List:
          print (x, end="")

Look at the difference in the output between Python 2 and Python 3:

Python 2:

>>> print

>>>

Python 3:

>>> print
<built-in function print>
>>> print()

>>>

A slightly more compact way of doing it would be like this:

for index, row in enumerate(tableau, start=1):
    print('Row {index} : {row}'.format(index=index, row=' '.join(row)))
Blender
  • 289,723
  • 53
  • 439
  • 496
1

You need to change your prints to be functions.

for List in tableau:
    print()
    print ("Row", Row, ":", end="")
    print()
    Row += 1
    for x in List:
        print (x, end="")
Tim
  • 11,710
  • 4
  • 42
  • 43
0
  for List in tableau:
    print("\n")
    print ("Row", Row, ":", "")

    print("\n")
    Row += 1
    for x in List:
        print (x, end="")

That should do the trick. It worked for me.

Games Brainiac
  • 80,178
  • 33
  • 141
  • 199