如何在Python中获取输入数组?

问题描述 投票:-2回答:1

我想接受这样的输入。这里2是测试用例的数量4是数组中输入的数量。这是输入示例。

2

4

1 5 3 2

3

3 2 7

python-3.x
1个回答
0
投票

这是您要寻找的吗?

test_cases = []
number_of_cases = input ('Enter the number of test cases : ')
for index in range (int (number_of_cases)) :
    test_cases.append ([]) 
    prompt = 'Enter the number of digits for test ' + str (index + 1) + ' : '
    number_of_digits = input (prompt)
    for count in range (int (number_of_digits)) :
        prompt = 'Enter test case number ' + str (count + 1) + ' : '
        test_cases[index].append (input (prompt))
print (test_cases)
© www.soinside.com 2019 - 2024. All rights reserved.