如何在列表的值周围打印一些内容?
我的程序允许您写入时间(它们被放在列表中),并且列表中最高和最低的时间被排除在外,然后计算剩余时间的平均值。
然后我告诉该程序要在列表中打印出时间和平均值,输出看起来像这样:
[1.1、2.1、3.1、4.1、5.1]平均值:x
我希望它放置括号的平均时间最高和最低时间(排除在外的时间)。如果在没有[]
的情况下显示时间,我也会喜欢它,看起来像这样:
(1.1),2.1,3.1,4.1,(5.1)平均值: X
我一直在扫描Internet寻求解决方案,但是我没有成功,我想这是一个非常具体的问题。
谁能告诉我是否可以做,如果是这样?如果可能的话,我会很感激一个非常简单的解释,但是如果需要的话,我会很乐意学到相对先进的东西。 (如果重要的话,idk,但我正在使用Python 3)
My program allows you to write in times (they get put in a list) and the highest and lowest time of the list gets excluded and it then calculates the average of the remaining times.
Then I told the program to print out the times in the list and the average, the output looks something like this:
[1.1, 2.1, 3.1, 4.1, 5.1] average:x
I want it to put parentheses around the highest and the lowest times of the average (the ones that are excluded). I'd also like it if the times were displayed without the []
around them, which would look something like this:
(1.1), 2.1, 3.1, 4.1, (5.1) average:x
I've been scanning the internet for a solution to this but I've had no success, I guess it's a very specific problem.
Can anyone tell me if it's possible to do and if so how? I'd appreciate a pretty simple explanation, if possible, but I'll gladly learn something relatively advanced if I have to. (idk if it matters but I am using python 3)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要格式化结果,如果您使用的是Python 3.6或更高版本,则可能使用F-string:
gives:
编辑:
如果您使用的是较早版本,则可以使用
%语法,例如:
它将给出:
You want to format the results, probably using f-string if you're using Python 3.6 or above:
gives:
Edit:
If you are on an earlier version, you can use
%
syntax, e.g.:which will give: