Python程@2011-10-03
行境: python 3
是有趣的部分,因有答案,所以中list使用了sort()
所以最小值就是 inputs[0],然最大值是list最後一值,也就是 inputs[-1:][0]
上的25行好
print("Type integers, each followed by Enter; or just Enter to finish")total = 0count = 0inputs = []while True: line = input("integer:") if line: try: number = int(line) inputs += [number] except ValueError as err: print(err) continue total += number count += 1 inputs.sort() else: breakif count: print("nmbers:", inputs) print("count=", count, "total=", total, "lowest=", inputs[0], "highest=", inputs[-1:][0], "mean=", total/count)