这只是一个介绍性的类代码,我想知道如何找到所有next_value变量的最大值并将其与first_value进行比较以打印最大值。我的if语句是接近,但我不知道如何解决它查找循环中的最大值
maximum = 0.0
value = int(input("Enter the number of values to process: "))
first_value = float(input("First value: "))
next_value_total = 0
for i in range(1, value):
next_value = float(input("Next value: "))
next_value_total += next_value
if first_value <= next_value:
maximum = next_value
elif first_value > next_value:
maximum = first_value
total = next_value_total + first_value
print("The total is {:.1f}".format(total))
print("The maximum is {:.1f}".format(maximum))
那么,有什么问题呢? –
它并不总是正确打印最大值 –