如何让程序找到最低限度

时间:2014-02-13 19:31:47

标签: drop-down-menu

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)

当我运行该程序时,它给出了相同的距离,以获得关于如何获得最小值的最大值和最小值?

1 个答案:

答案 0 :(得分:0)

假设这是python

distance是一个浮点数,因此max([distance])将等于distance

你可以通过多种方式解决它

一种简单的方法是将最大值初始化为非常小的值,将最小值初始化为非常大的值并更改这些行:

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

为:

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