我输入了这段代码:
def game():
down, right = 0, 0
while 1:
for i in range(down):
print "00000000000000000000000000000000000000000000000000000000000000000000000000000000"
for j in range(right):
print "0",
print "S",
for j in range(80 - (right + 1)):
print "0",
for i in range(38 - (down + 1)):
print "00000000000000000000000000000000000000000000000000000000000000000000000000000000"
direction = raw_input("Direction?")
if(direction.upper() == "W"):
down -= 1
elif(direction.upper() == "S"):
down += 1
elif(direction.upper() == "A"):
right -= 1
elif(direction.upper() == "D"):
right += 1
game()
'print“S”,'应该在结尾处有逗号,以便在下次调用打印功能时停止在下一行打印。
实际的事情是这样的:(我切断了一些包含“000000”的行)
S 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000
为什么第一个零之间有空格?我的打印功能没有空格。
答案 0 :(得分:3)
print "0",
表示print
“0”,print
表示空格。
逗号基本上会导致print
输出空格而不是换行符。如果您想避开此行为,请改用sys.stdout.write()
。
答案 1 :(得分:3)
您可以在每False
,
print "S",
sys.stdout.softspace = False
但是你也可以使用sys.stdout.write()