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