2014-02-13 52 views
0
list = "\n==== Names and Distances ====\n" 
firstName = input ("Enter next person's first name >") 
while firstName > "": 
    distance= float(input("Enter distance thrown: ")) 
    list = list + firstName + "." + str(distance) + "\n" 
    firstName = input ("Enter next person's first name >") 
    largest = max([distance]) 
    smallest = min([distance]) 
print (list) 
print ("the longest distance is: " + str(largest)) 
print (smallest) 

當我運行程序時,它給了我相同的最大和最小距離關於如何得到最小值的任何想法?如何讓程序找到最小值

回答

0

假設這是蟒蛇

distance是float所以max([distance])將等於distance

你可以解決它在許多方面

一個簡單的方法是初始化最大的是一個很小的值和最小的值成爲非常大的值並且改變這些行:

largest = max([distance]) 
smallest = min([distance]) 

到:

largest = max(largest,distance) 
smallest = min(smallest,distance)