[Python] Explain taking multiple lines of input in python - example from hackerrank

Discussão em 'Python' iniciado por Stack, Março 1, 2025.

  1. Stack

    Stack Membro Participativo

    I'm relatively new to python and coding in general, and I'm working through some practice exercises on HackerRank. In the one I'm working on right now, several lines of input are given, as follows:

    (In context this is n number and length of arrays, followed by the arrays)

    3

    11 2 4

    4 5 6

    10 8 -12


    I need to access all lines of this input but as I said I'm quite new to this and not sure how. When I try to print input it only gives me the first line.

    I saw in another HackerRank problem with multiple lines of input that this code was used:

    n = int(input().strip())

    arr = []

    for _ in range(n):
    arr.append(list(map(int, input().rstrip().split())))


    Can someone please explain to me what's going on here? It's clearly accessing all the input but I don't understand how.

    Continue reading...

Compartilhe esta Página