def ShowMinValue(listofvalues):
x = float(listofvalues[0])
for i in range(len(listofvalues)):
if x > float(listofvalues[i]):
x = float(listofvalues[i])
return x
print ShowMinValue([5,'0.1',6,4,3,7,4,1,234,'2239429394293',234656])
返回 0.1
现在,要为其设置一个变量,只需输入:
variable = ShowMinValue(listOfPossibleNumbers)
如果你想要一个永不例外的版本:
def ShowMinValue(listofvalues):
try:
x = createdMaxDef(listofnumbers) #Your maximum possible number, or create an max() def to set it. to make it, set that '>' to '<' and rename the method
except Exception:
pass
for i in range(len(listofvalues)):
try:
if x > float(listofvalues[i]):
x = float(listofvalues[i])
except Exception:
pass
return x
print ShowMinValue([5,'0.1',6,4,'',3,7,4,1,234,'2239429394293',234656])
返回 2239429394293(将 '>' 更改为 '