例如,我有一行是“3 2 11”。我想将其拆分为3个“3”、“2”、“11”,然后将它们转换为整数,并将它们分配到各个变量中。我的代码如下:
import sys
for line in sys.stdin:
print(line, end="")
snailHasNotEscaped = True
days = 0
totalMs = 0
mPerWholeDay = N - M
while snailHasNotEscaped:
totalMs += mPerWholeDay
days += 1
if totalMs >= H:
snailHasNotEscaped = False
我假设您有未知数量的变量,所以我会将它们存储在列表中。
我将使用列表理解来构建新列表:
但是,您可以将其用于:
您可以使用映射功能:
或者如果您想使用快速I/O
这是单行线
如果输出中没有固定的变量,则
或
相关问题 更多 >
编程相关推荐