【问题标题】:How would i go about getting the total to show the actual total?我将如何让总数显示实际总数?
【发布时间】:2018-04-10 12:03:17
【问题描述】:
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))

目前总数等于我输入的整数数量,我理解它的来源 总计 = 总计 + 1 我将如何让总计成为输入的所有整数的总和?

【问题讨论】:

标签: python python-3.x


【解决方案1】:

做事

total = total + i

并检查行中的缩进

num = input('Enter an integer: ')

应该是内层一层

【讨论】:

  • 哇,修复了,谢谢,缩进只是我对这个景象不熟悉,所以我可能只是搞砸了
【解决方案2】:

您不需要循环。 Python有求和函数

total = sum(integers) 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-03
    • 2022-06-13
    相关资源
    最近更新 更多