我對python有點新,我最近遇到了這個問題,我無法確定如何找到最小值不使用python中的min或max函數的列表。以下是我的代碼:如何使用while循環同時在python中不使用min函數從列表中找到最小值
#Prompt user to enter a minimum of 5 round trip times separated with commas
roundTrips = input('Please enter at least 5 round trips seprated by ",": ')
#Check closest object
def closest_object(roundTrips):
roundTrips = list(roundTrips.split(','))
count = 0
minimum = 0
if len(roundTrips)<=4:
print('error')
else:
while count<len(roundTrips):
positions = roundTrips[count]
count += 1
if minimum or (int(positions)<minimum):
minimum = positions
print(minimum)
#Perform the parsing of roundTrips input here
closestObject = []
print('The closest object is',closestObject) #Modify to display the closest object
return closestObject#Do not remove this line
爲什麼你不能使用'min/max'?這是功課嗎? – ekhumoro
是的,我的講師告訴我可以在不使用min函數的情況下找到最小值。那麼,我試圖做他所說的,但無濟於事,因此我正在尋求幫助在這四米 –