Python Input Questions

Asked 1 years ago, Updated 1 years ago, 315 views

Number of input data in the first line n Data dimension k on the second line I want to get n pieces of k-dimensional data from the third line What should I do?

For example,

4
2
5 10
10 20
6 8
15 11
I'd like to type it like this.

n = int(input())
k = int(input())
---- How do I code this part?----

input python

2022-10-20 00:01

2 Answers

I understood that I would like to receive a two-dimensional array of NxK.

n = int(input())
k = int(input())

data = []
for i in range(n):
    data.append([])
    for j in range(k):
        data[-1].append(input())

print(data)

I think it'd be good to do it like this


2022-10-20 00:01

n = int(input())
k = int(input())

arr= []
for i in range(n):
    arr.append(list(map(int,input().split())))


2022-10-20 00:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.