我如何获得显示实际总数的总数?

时间:2018-04-10 03:49:40

标签: python python-3.x

i = 0
integers = []
total = 0
while i < 10:
num = input('Enter an integer: ')
    try:
        integers.append(int(num))
        i = i + 1
    except:
        print('Bad input')
for i in integers:
    total = total + 1
average = total / 10
print('this is the list of integers you entered: ',(integers))
print('The lowest number is: ',min(integers))
print('The highest number is: ',max(integers))
print('This is the average of all integers: ',(average))
sorted_list = sorted(integers)
print('The integers list sorted in ascending sequence: ',(sorted_list))
sorted_list.reverse()
print('The  integers list sorted in descending sequence: ',(sorted_list))

目前总数等于我输入的许多整数我明白了     total = total + 1我如何才能得到总数为所有输入的整数?

2 个答案:

答案 0 :(得分:2)

只做

total = total + i

并检查行中的缩进

num = input('Enter an integer: ')

它应该是一个层面的缺点

答案 1 :(得分:1)

你不需要循环。 Python有一个求和函数

total = sum(integers)