Respuesta :

Answer:

Here is the program:

user_input = input() #takes input from user

hourly_temperature = user_input.split() #split the input numbers into a list and stores them to hourly_temperature

for i in range(len(hourly_temperature)): #iterates through the hourly_temperature

    if i !=len(hourly_temperature)-1: #if i is not positioned to last element

         print(hourly_temperature[i],"->", end=' ') #displays the elements separated with a -> surrounded by spaces

    else: #if i points to the last element of hourly_temperature

         print(hourly_temperature[i]," \n") #prints the last element with a space and new line after it

Explanation:

Lets say the user inputs the following numbers:

90 92 94 95

Now these are split into a list and are stored in hourly_temperature:

['90', '92', '94', '95']                                                                                                      

Now the for loop: for i in range(len(hourly_temperature)): iterates through each item in the hourly_temperature. The if condition                                      if i !=len(hourly_temperature)-1: checks each item by using i as index to that item. If i is not positioned to the last item of hourly_temperature (in this example last element is 95) then the print statement print(hourly_temperature[i],"->", end=' ') keeps printing the items in hourly_temperature (90,92 and 94) separated with a -> surrounded by spaces as:

90 -> 92 -> 94 ->

When i is positioned to the last element i.e. 95 then else part executes :print(hourly_temperature[i]," \n")                                                                                                 which prints 95 to the end of the above output and adds a space and a new line after 95

So the entire output of the above examples is:

90 -> 92 -> 94 -> 95                                                                                                          

However this also works on the strings just like it worked on these integers.

The screenshot of the program along with its output is attached.

Ver imagen mahamnasir