Home > other >  Why run want to seek the maximum, the result is always zero?
Why run want to seek the maximum, the result is always zero?

Time:05-08

 def compare (x, y) : 
Return the if x x & gt; Y the else y
Def max_value list_data (*) :
Value=https://bbs.csdn.net/topics/list_data [0]
For x in range (1, len (list_data) :
Value=https://bbs.csdn.net/topics/compare (list_data [x], value)
Value=https://bbs.csdn.net/topics/0
5,6,3,5463,6,7,45,725,723,7,3,46,86,7,56,8,567,5,5745,26,34,63,412,35,4,76585,67,3,45,4,5,34,5,47,5686 max_value (42323457424)
Print (value)

CodePudding user response:

 
Def compare (x, y) :
Return the if x x & gt; Y the else y
Def max_value list_data (*) :
Global value
Value=https://bbs.csdn.net/topics/list_data [0]
For x in range (1, len (list_data) :
Value=https://bbs.csdn.net/topics/compare (list_data [x], value)
Value=https://bbs.csdn.net/topics/0
5,6,3,5463,6,7,45,725,723,7,3,46,86,7,56,8,567,5,5745,26,34,63,412,35,4,76585,67,3,45,4,5,34,5,47,5686 max_value (42323457424)
Print (value)

76585

Because of a local variable in a function value blocked outside of the global value

CodePudding user response:

 

Def compare (x, y) :
Return the if x x & gt; Y the else y
Def max_value list_data (*) :
Value=https://bbs.csdn.net/topics/list_data [0]
For x in range (1, len (list_data) :
Value=https://bbs.csdn.net/topics/compare (list_data [x], value)
The return value
5,6,3,5463,6,7,45,725,723,7,3,46,86,7,56,8,567,5,5745,26,34,63,412,35,4,76585,67,3,45,4,5,34,5,47,5686 value=https://bbs.csdn.net/topics/max_value (42323457424)
Print (value)

  • Related