【发布时间】:2022-11-30 07:59:29
【问题描述】:
编写一个循环来打印 hourly_temperature 中的所有元素。用空格包围的 -> 分隔元素。带有输入的给定程序的示例输出:
90 92 94 95' 90 -> 92 -> 94 -> 95
注意:95 后跟一个空格,然后是换行符。
这是作业 到目前为止,这是我的代码:
user_input = input()
hourly_temperature = user_input.split()
lst_str=""
for temp in hourly_temperature:
lst_str+=str(temp)+ " -> "
print(lst_str, end=" ")
这是我的代码的输出:
90 -> 92 -> 94 -> 95 ->
我如何才能在列表中的最后一个数字之后不包含“->”?
【问题讨论】:
-
一行代码:
print(' -> '.join(hourly_temperature))
标签: python