In python 3 , there have been answers about how to replace an existing output with another. These answers suggest the use of end='\r' ad in print('hello', end='\r') This is working ofcourse, but it works only for one line .
In the program that I post below, I first output 5 lines which is the representation of a table matrix. The user is asked to type one number (1-3) and then the matrix is printed again with an 'X' in the position that the user indicated.
But as you can see, the matrix is printed below the initial one. How can I replace the existing output ?
If I use the end = '\r' it will just move the cursor to the beginning of the line. But this will not work for me because I want to print 5 lines , and then move the cursor to the beginning of the first line, and not to the beginning of the fifth line (as the end='\r' does).
How could I achieve this in python ?
from __future__ import print_function
list1=[' '*11,'|',' '*7,'|',' '*10]
def board():
print ('\t \t | \t \t |')
print (list1)
print ('\t \t | \t \t |')
#print '\n'
print
def playerone():
player1 = raw_input("PLAYER1: enter your position 1-3: ")
if (player1 == '1'):
list1[0]=' '*5 + 'X'+' '*5
elif (player1=='2'):
list1[2]=' '*3 + 'X'+' '*3
elif (player1=='3'):
list1[4]=' '*3 + 'X'+' '*6
else:
playerone()
print ('our board is : ')
board()
playerone()
print ('our board is :')
board()