find the maximum number in a list using a loop

后端 未结 10 1535
野趣味
野趣味 2021-01-02 23:16

So I have this list and variables:

nums = [14, 8, 9, 16, 3, 11, 5]

big = nums[0]

spot = 0

I\'m confused on how to actually do it. Please

10条回答
  •  心在旅途
    2021-01-03 00:15

    nums = [14, 8, 9, 16, 3, 11, 5]
    
    big = None
    
    spot = None
    
    for i, v in enumerate(nums):
        if big is None or v > big:
             big = v
             spot = i
    

提交回复
热议问题