Freddy Freddy - 7 months ago 12
Python Question

How to remove parenthesis, comma and Quotation mark

I am trying to print chessboard with "."(dot) and "*"asterisk. Suppose input is 33 i need to print 3 X 3 chessboard.

my code works something like this:

32
('*', '.')
('.', '*')
*.


I don't know why there is parenthesis, comma and Quotation mark.

here's is my code:

row = raw_input()
row = int(row)
count = 0

a = "*"
b = "."

while True:
count = count +1




if ((int(str(row)[0]))%2 == 0) and ((int(str(row)[1]))%2 == 0):
print (a,b) * (int(str(row)[1])/2)
print (b,a) * (int(str(row)[1])/2)

elif ((int(str(row)[0]))%2 != 0) and ((int(str(row)[1]))%2 == 0):
print (a,b) * (int(str(row)[1])/2)
print (b,a) * (int(str(row)[1])/2)


elif ((int(str(row)[0]))%2 == 0) and ((int(str(row)[1]))%2 != 0):
print (a,b) * (int(str(row)[1])/2), "*"
print (b,a) * (int(str(row)[1])/2), "."

elif ((int(str(row)[0]))%2 != 0) and ((int(str(row)[1]))%2 != 0):
print (a,b) * (int(str(row)[1])/2), "*"
print (b,a) * (int(str(row)[1])/2), "."


if (int(str(row)[0]))%2 == 0 and count == (int(str(row)[0]))/2 :
break

elif (int(str(row)[0]))%2 != 0 and count == (int(str(row)[0]))/2:
print "*."
break


I used logic "a" * 4 will print aaaa but it is not printing like that!




P.S. I know few stuff are still not working like single digit boards and any board which contains 1.

Answer

Instead of (a,b) * number use (a+b) * number. (a,b) is a tuple whereas (a+b) is a string.