Home > other >  Python Max value
Python Max value

Time:09-28

Max value is equal to the Numbers (0)
Max value only need is greater than the first number is the Max value:

CodePudding user response:

Can you determine the largest number, you can not than the
If,6,10,2,8,4 [3], it is not big than the first one is the biggest, so take more than one by one, each larger than a left

CodePudding user response:

There is nothing wrong with code written

CodePudding user response:

In fact than every time, because the program doesn't know the first is the largest, than after just know,

CodePudding user response:

 
Numbers=[10, 8, 6, 2, 8, 4]
Max=Numbers [0]
For number in Numbers:
If the number & gt; Max:
Max number of=
Print (number)
Print (Max)


Take the maximum value, can also sort first, and then take the last value
 
Numbers=[10, 8, 6, 2, 8, 4]
Numbers. The sort ()
Print (Numbers)
Print (Numbers [len (Numbers) - 1))

CodePudding user response:

May also directly using the built-in function:

 
Numbers=[10, 8, 6, 15, 2, 8, 4]
Print (Max) (Numbers) # print maximum
Print (min (Numbers) # print the minimum


  • Related