使用循环在列表中找到最大数目 [英] find the maximum number in a list using a loop
本文介绍了使用循环在列表中找到最大数目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我有此列表和变量:
So I have this list and variables:
nums = [14, 8, 9, 16, 3, 11, 5]
big = nums[0]
spot = 0
我对如何实际执行感到困惑.请帮忙!我是Python的新手,我想用这个练习来给我一个入门.我想像在Scratch或BYOB中一样从重复列表长度"开始,但是如何在Python上做到这一点?
I'm confused on how to actually do it. Please help! I'm new to Python and I want to use this exercise to give me a starter. I want to start with "repeat length of list" like in Scratch or BYOB, but how do I do that on Python?
推荐答案
通常,您可以使用
max(nums)
如果您明确想使用循环,请尝试:
If you explicitly want to use a loop, try:
max_value = None
for n in nums:
if n > max_value: max_value = n
这篇关于使用循环在列表中找到最大数目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文