给定两个数字的输入,如何在换行符上打印数字列表的切片范围

How to print a sliced range of numbers list on newline given an input of two numbers

我有一个范围在 1 到 20 之间的列表。

我在单行中输入两个数字 ij 并用 space 分隔以对列表进行切片。

需要在换行符上打印切片数字。我做了以下事情:

list_1 = list(range(1,20))
i,j = [int(i) for i in input().split()]

print(list[i:j]); 

例如

输入10 13

输出11, 12, 13

我想要 newline_output。我尝试使用 sep='\n',但它失败了。我错过了什么?

print("\n".join([str(item) for item in list])); 

这应该会给你想要的输出。

试试这个:

list_1 = list(range(1,20))
i,j = [int(i) for i in input().split()]
print(*list_1[i:j], sep="\n")