[Python] Printing array elements separated by -> has extra separator at front

Discussão em 'Python' iniciado por Stack, Fevereiro 16, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to write a loop to print all elements in hourly_temperature, separating elements with a -> surrounded by spaces.

    Sample output for the given program with input: '0 92 94 95' 90 -> 92 -> 94 -> 95

    Note: 95 is followed by a space, then a newline.

    Testing with input: 90 92 94 95 and: -32 -35 -42

    user_input = input() hourly_temperature = user_input.split()

    hourly_temperature = [90, 92, 94, 95]

    s = "" for t in hourly_temperature: s += " -> " + str(t)


    At this stage, s contains -> 90 -> 92 -> 94 -> 95 so I need to remove the first ->

    I'm doing this by keeping everything from character 4 onwards, like this: print(s[4:])

    I tried this but it did not pass for the expected input, -32 -> -35 -> -42

    Continue reading...

Compartilhe esta Página