python中的循环的最小/max

发布于 2025-02-02 21:39:25 字数 138 浏览 2 评论 0原文

如果需要获取此循环的最小值,最大和总和,请如何运行此代码?

我成功地运行了这个循环,但是当我试图获取最小值时,Max Am获得“ int”“对象是不可能的”。

对于范围(1,1000)的价值: 打印(最小值(值))

谢谢

Please how can I run this code if I need to get the MIN, MAX and SUM of this Loop?

I ran this loop successfully but when I was trying to get the MIN and MAX am getting "int" "the object is not iterable".

for value in range(1,1000):
print(min(value))

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

离笑几人歌 2025-02-09 21:39:25

是的,因为Min()函数返回具有最低值的项目,或者在峰值中具有最低值的项目。意味着,当您运行循环时,您的获得I仅为1,并且由于单个值而进行最小迭代。只是您没有任何比较价值。尝试添加更多代码

例子,

a = list()

for value in range(1,1000): 
    a.append(value)
    if value==999:
           print("min of 1 to 1000 is\t", min(a))

Yes, because The min() function returns the item with the lowest value, or the item with the lowest value in an iterable. Means when you are running your loop your getting i as 1 only and min iterating due to single value. simply you're not having any value for comparison. try to add more code.

example,

a = list()

for value in range(1,1000): 
    a.append(value)
    if value==999:
           print("min of 1 to 1000 is\t", min(a))
‖放下 2025-02-09 21:39:25

MIN在可估量的列表中找到最小值,最低([1,2,3,4])
您正在尝试找到单个整数的最小值,即min(1),因为循环从您正在通过的值范围返回每个值

Min finds the minimum value in an iterable e.g. a list, min([1,2,3,4])
You are trying to find the minimum value of a single integer i.e. min(1) because the loop returns each value from the range of values you are iterating through

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文