我已经写了这个代码,使打印出一个新的行后,我提供了一行输入。。像这样的事情
netM = ''
while True:
line = raw_input()
if not line: break
netM += '' + line
netMs = netM.replace('.', '')
print("\n" + netMs + " = " + netMs + " or " + netM + "\n")
假设我进去了
Pause.now
它会输出。。你知道吗
Pausenow = Pausenow or Pause.now
但我想一次做很多台词,所以它会这样做。。你知道吗
Pausenow = Pausenow or Pause.now
Pausenow1 = Pausenow1 or Pause.now1
Pausenow2 = Pausenow2 or Pause.now2
如果我进去了
Pause.now
Pause.now1
Pause.now2
等等。你知道吗
但它却做到了这一点。你知道吗
pauseNowpauseNow1pauseNow2 = pauseNowpauseNow1pauseNow2 or pause.Nowpause.Now1pause.Now2
这是因为raw\u input()将输入作为单个字符串。你知道吗
您还为每个输入的行向newM变量添加了输入的行输入。它应该在for loop里面。定义其他断点,而不是默认的“新行”。你知道吗
在这里,我使用断点作为“”即空字符串。现在,当您输入空字符串时,这个循环将中断。你知道吗
您需要为循环的每个迭代打印行,否则它将继续向上一个循环追加新行,只需将您的print语句移到while循环中即可 同样,对于您想要的结果,不要在
netM
变量中追加行在我看来,应该将单个字符串添加到主字符串(netM)中,除以
'\n'
,然后在循环中断时打印整个主字符串。你知道吗相关问题 更多 >
编程相关推荐